-1

I have a UniformGrid containing all my video thumbnails taken (they are all System.Windows.Control.Image). My goal here is to save a jpg of all the thumbnails after I click a button. Is there a way to grab a bitmap image or something from a UbiformGrid? I am using C# with WPF.

Edit: like a screenshot. But I don't want to window border, only the grid content.

Edit2: I finally found a solution. Thanks for the help.

RenderTargetBitmap renderTarget = new RenderTargetBitmap((int)ThumbnailPanel.Width, 

(int)ThumbnailPanel.Height, 96, 96, PixelFormats.Pbgra32);
VisualBrush sourceBrush = new VisualBrush(ThumbnailPanel);
DrawingVisual drawingVisual = new DrawingVisual();
DrawingContext drawingContext = drawingVisual.RenderOpen();
using (drawingContext)
{
    drawingContext.DrawRectangle(sourceBrush, null, new Rect(new Point(0, 0), new Point(ThumbnailPanel.Width, ThumbnailPanel.Height)));
}
renderTarget.Render(drawingVisual);
JpegBitmapEncoder jpgEncoder = new JpegBitmapEncoder();
jpgEncoder.QualityLevel = 80;
jpgEncoder.Frames.Add(BitmapFrame.Create(renderTarget));
Byte[] _imageArray;
using (MemoryStream outputStream = new MemoryStream())
{
    jpgEncoder.Save(outputStream);
    _imageArray = outputStream.ToArray();

}
FileStream fileStream = new FileStream(@"myThumbnails.jpg", FileMode.Create, FileAccess.ReadWrite);
BinaryWriter binaryWriter = new BinaryWriter(fileStream);
binaryWriter.Write(_imageArray);
binaryWriter.Close();
Steve Konves
  • 2,648
  • 3
  • 25
  • 44
Sophie
  • 324
  • 3
  • 12
  • Please post what you found as an answer, or at least as an edit in your question. That way, others can benefit from what you found. – Steve Konves Oct 22 '12 at 18:30

1 Answers1

0

Sure, just iterate through your collection of images with for or foreach and use the Image.GetThumbnailImage method from the System.Drawing namespace to create thumbnails... it's that simple.

For example:

foreach (var img in myImages)
{
  var thumb = image.GetThumbnailImage(thumbnailSize.Width, thumbnailSize.Height, null, IntPtr.Zero);
  //Do something with the thumbnail
  thumb.Save(output)
}
Dean Kuga
  • 11,878
  • 8
  • 54
  • 108
  • Maybe it wasnt clear enough, i didnt want to save each image seperatly but all together. But i finaly came up with something that satifies me: – Sophie Oct 22 '12 at 17:27