// I made use of WriteableBitmap by the following piece code in a freely downloadable photoscroll application I downloaded.
// I replaced DoLoadImage method of the Photoscroll app with:
double renderHeight = 40 * 40;// actualHeight* scale;
double renderWidth = 40 * 40;// actualWidth* scale;
RenderTargetBitmap renderTarget = new RenderTargetBitmap((int)renderWidth, (int)renderHeight, 6, 6, PixelFormats.Pbgra32);
DrawingVisual drawingVisual = new DrawingVisual();
DrawingContext drawingContext = drawingVisual.RenderOpen();
BitmapDecoder imgDecoder = BitmapDecoder.Create(new Uri(@"c:\sunset1.jpg", UriKind.Absolute), BitmapCreateOptions.None, BitmapCacheOption.None);//.PreservePixelFormat
BitmapFrame frame = imgDecoder.Frames[0];
TransformedBitmap thumbnail = new TransformedBitmap();
thumbnail.BeginInit();
thumbnail.Source = frame as BitmapSource;
int pixelH = frame.PixelHeight;
int pixelW = frame.PixelWidth;
int decodeH = 240;
int decodeW = (frame.PixelWidth * decodeH) / pixelH;
double scaleX = decodeW / (double)pixelW;
double scaleY = decodeH / (double)pixelH;
TransformGroup transformGroup = new TransformGroup();
thumbnail.Transform = transformGroup;
thumbnail.EndInit();
int i = 0;
using (drawingContext)
{
drawingContext.PushTransform(new ScaleTransform(200 + i, 200 + i));
drawingContext.DrawLine(new Pen(Brushes.GreenYellow, 1),
new Point(10.0, 10.0),
new Point(215.0, 210.0));
//.DrawLine(myPen.Brush, 10, 5 - 5, 10 + 5, 5 - 5);
//.DrawRectangle(myPen.Brush, myPen, null, new Rect(new Point(0, 0), new Point(actualWidth, actualHeight)));
}
renderTarget.Render(drawingVisual);
//_imageSource = frame.Thumbnail;
// we'll make a reasonable sized thumnbail with a height of 240
// while (i <= 100)
{
transformGroup.Children.Add(new ScaleTransform(scaleX+i, scaleY+i));
WriteableBitmap writable = new WriteableBitmap(renderTarget);
writable.Freeze();
_imageSource = writable;
i = i + 1;
}
|