private Image CreateThumbnailImage(Stream stream, int width)
{
BitmapImage bi = new BitmapImage();
bi.SetSource(stream);
double cx = width;
double cy = bi.PixelHeight * (cx / bi.PixelWidth);
Image image = new Image();
image.Source = bi;
WriteableBitmap wb1 = new WriteableBitmap((int)cx, (int)cy);
ScaleTransform transform = new ScaleTransform();
transform.ScaleX = cx / bi.PixelWidth;
transform.ScaleY = cy / bi.PixelHeight;
wb1.Render(image, transform);
wb1.Invalidate();
WriteableBitmap wb2 = new WriteableBitmap((int)cx, (int)cy);
for (int i = 0; i < wb2.Pixels.Length; i++)
wb2.Pixels[i] = wb1.Pixels[i];
wb2.Invalidate();
Image thumbnail = new Image();
thumbnail.Width = cx;
thumbnail.Height = cy;
thumbnail.Source = wb2;
return thumbnail;
}
Put that somewhere, then...
byte[] bytes = null;
CreateThumbnailImage(new System.IO.MemoryStream(bytes), 200));
maybe then something like this
datagrid1.items.add(imagehere);
Or you can use a view model view approach and bind the image, basically the hard part is done you now have the image.
The above method is something I found here:
http://www.wintellect.com/blogs/jprosise/silverlight-s-big-image-problem-and-what-you-can-do-about-it[
^]
There are other ways but this way is geared towards silverlight, for lower memory consumption, I took a wild guess that you are probably using silverlight.