1

i have function which will create the thumbnail image :

Image photo=System.Drawing.Image.FromStream(myFile.InputStream);

Bitmap bmp = new Bitmap(100, 100);
Graphics graphic = Graphics.FromImage(bmp);
graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphic.SmoothingMode = SmoothingMode.HighQuality;
graphic.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphic.CompositingQuality = CompositingQuality.HighQuality;
graphic.DrawImage(photo, 0, 0, 100, 100);

The bmp image will be in bitmap format.
How do I convert it so I assign in image tag and display on a page?

Ashley Medway
  • 7,151
  • 7
  • 49
  • 71
bhakti
  • 143
  • 1
  • 1
  • 9

2 Answers2

1

You can return byte array in following way.

MemoryStream stream = new MemoryStream();
bmp.Save(stream, ImageFormat.Jpeg);
Byte[] buffer = new byte[0];
buffer = stream.ToArray();
return buffer;

and using generic handler you can show this data in image tag.

Ashley Medway
  • 7,151
  • 7
  • 49
  • 71
0

I build a snippet from several ideas, this works perfectly:

 Bitmap original = new Bitmap(@"C:\path\img.jpg");
 Rectangle srcRect = new Rectangle(0, 0, 100, 100);
 Bitmap cropped = (Bitmap)original.Clone(srcRect, original.PixelFormat);
 byte[] imgbytes;    
 using (MemoryStream stream = new MemoryStream())
 {
        cropped.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
        imgbytes = stream.ToArray();
 }
 <img src="@String.Format("data:image/png;base64,{0}", Convert.ToBase64String(imgbytes))" />

Within the Rectangle the offset is (0,0) and crops 100x100 Pixels from the orignal.

blu3drag0n
  • 61
  • 4