
stream.Close();
}
public static byte[] GetJpgImage(UIElement source, double scale, int quality)
{
Byte[] imageArray;
double actualHeight = source.RenderSize.Height;
double actualWidth = source.RenderSize.Width;
double renderHeight = actualHeight * scale;
double renderWidth = actualWidth * scale;
RenderTargetBitmap renderTarget = new RenderTargetBitmap((int)renderWidth, (int)renderHeight, 96, 96, PixelFormats.Pbgra32);
VisualBrush sourceBrush = new VisualBrush(source);
DrawingVisual drawingVisual = new DrawingVisual();
DrawingContext drawingContext = drawingVisual.RenderOpen();
using (drawingContext)
{
drawingContext.PushTransform(new ScaleTransform(scale, scale));
drawingContext.DrawRectangle(sourceBrush, null, new Rect(new Point(0, 0), new Point(actualWidth, actualHeight)));
}
renderTarget.Render(drawingVisual);
JpegBitmapEncoder jpgEncoder = new JpegBitmapEncoder();
jpgEncoder.QualityLevel = quality;
jpgEncoder.Frames.Add(BitmapFrame.Create(renderTarget));
using (MemoryStream outputStream = new MemoryStream())
{
jpgEncoder.Save(outputStream);
imageArray = outputStream.ToArray();
}
return imageArray;
}

sayali nagawadePosted Nov 11, 2011, 1:50 AM
public static byte[] GetJpgImage(UIElement source, double scale, int quality) giving error for UIElement source;
LanaPosted Jul 15, 2011, 9:00 PM
very helpful,thanks
Dinesh BeniwalPosted Jul 15, 2011, 3:34 AM
Welcome to the Mindcracker Community, thanks for sharing
Angelina ErinPosted Jul 15, 2011, 1:32 AM
Good Job Benjamin