google

Newest Post

Showing posts with label Resize. Show all posts
Showing posts with label Resize. Show all posts

Convert base64 into Image, Resize the image and again convert it into base64

| Saturday, March 5, 2016
Read more »
Convert base64 into Image, Resize the image and again convert it into base64

Use Following Code:

                       byte[] bytes = (byte[])row["Picture"];

                        Image image;

                       //Convert byte[] into image
                        using (MemoryStream ms = new MemoryStream(bytes))
                        {
                            image = Image.FromStream(ms);
                        }

                        // Resize the image
                        Bitmap b = new Bitmap(200, 200);
                        Graphics g = Graphics.FromImage((Image)b);
                        g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                        g.DrawImage(image, 0, 0, 200, 200);
                        g.Dispose();
                        image = (Image)b;

                        using (MemoryStream ms = new MemoryStream())
                        {
                            // Convert Image to byte[]
                            image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                            byte[] imageBytes = ms.ToArray();

                            // Convert byte[] to Base64 String
                            string base64String = Convert.ToBase64String(imageBytes);
                            obj.StudentPicture = base64String;
                        }

Convert base64 into Image, Resize the image and again convert it into base64

Posted by : Stranger
Date :Saturday, March 5, 2016
With 0comments
Prev
▲Top▲