Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - saving image from inkcanvas

 
 
Old 03-08-2006   #1 (permalink)
madhur


 
 

saving image from inkcanvas

Hello
I am trying to create an image file from the inkcanvas.
I have got the following code from some blog but the error comes that
BitmapVisualManager is inaccessible due to its protection level.

I dont know how the same code works in others people.

RenderTargetBitmap rtb = new
RenderTargetBitmap((int)inkCanvas1.Width, (int)inkCanvas1.Height, 96d,
96d,PixelFormats.Default);
BitmapVisualManager bvm = new BitmapVisualManager(rtb);

// draw the ink strokes onto the bitmap
DrawingVisual dvInk = new DrawingVisual();
DrawingContext dcInk = dvInk.RenderOpen();
dcInk.DrawRectangle(inkCanvas1.Background, null, new
Rect(0d, 0d,inkCanvas1.Width, inkCanvas1.Height));
foreach (Stroke stroke in inkCanvas1.Strokes)
{
stroke.Draw(dcInk);
}
dcInk.Close();
//bvm.Render(dvInk);

//save bitmap to file
FileStream fs = File.Open(@"c:\test.bmp",
FileMode.OpenOrCreate);
System.Windows.Media.Imaging.JpegBitmapEncoder encoder1 =
new JpegBitmapEncoder();
encoder1.Frames.Add(BitmapFrame.Create(rtb));
encoder1.Save(fs);


// BitmapEncoderBmp encoder = new BitmapEncoderBmp();
// encoder.Frames.Add(BitmapFrame.Create(rtb));
// encoder.Save(fs);
fs.Close();


My System SpecsSystem Spec
Old 03-14-2006   #2 (permalink)
Shawn A. Van Ness [MS]


 
 

Re: saving image from inkcanvas

BitmapVisualManager is internal now -- all you need is
RenderTargetBitmap.

Here's a snippet of code I pulled from an application which works on
Feb CTP... you shouldn't need to draw each Stroke into the DC, just
send the whole InkCanvas to the RenderTargetBitmap.Render.

HTH,
-S

// Must extend canvas bounds to cover whole grid.
_inkCanvas1.Width = _grid1.ActualWidth;
_inkCanvas1.Height = _grid1.ActualHeight;

UpdateLayout();

// Render visual to bitmap, and save to clipboard.
RenderTargetBitmap rtb = new RenderTargetBitmap(
(int)_bkgrndImage.Width, (int)_bkgrndImage.Height,
96d, 96d, PixelFormats.Default);

rtb.Render(_inkCanvas1);

// Crop to strokes' bounds, plus some margin (but contstained to
InkCanvas extent).
Rect bounds = _inkCanvas1.Strokes.GetBounds();
bounds.Inflate(20, 20);
bounds.Intersect(new Rect(0d, 0d, _inkCanvas1.ActualWidth,
_inkCanvas1.ActualHeight));

Int32Rect boundsI = new Int32Rect((int)bounds.X, (int)bounds.Y,
(int)bounds.Width, (int)bounds.Height);
CroppedBitmap bmp = new CroppedBitmap(rtb, boundsI);

// Push resulting image to clipboard.
Clipboard.SetImage(bmp);


madhur wrote:
> Hello
> I am trying to create an image file from the inkcanvas.
> I have got the following code from some blog but the error comes that
> BitmapVisualManager is inaccessible due to its protection level.
>
> I dont know how the same code works in others people.
>
> RenderTargetBitmap rtb = new
> RenderTargetBitmap((int)inkCanvas1.Width, (int)inkCanvas1.Height, 96d,
> 96d,PixelFormats.Default);
> BitmapVisualManager bvm = new BitmapVisualManager(rtb);
>
> // draw the ink strokes onto the bitmap
> DrawingVisual dvInk = new DrawingVisual();
> DrawingContext dcInk = dvInk.RenderOpen();
> dcInk.DrawRectangle(inkCanvas1.Background, null, new
> Rect(0d, 0d,inkCanvas1.Width, inkCanvas1.Height));
> foreach (Stroke stroke in inkCanvas1.Strokes)
> {
> stroke.Draw(dcInk);
> }
> dcInk.Close();
> //bvm.Render(dvInk);
>
> //save bitmap to file
> FileStream fs = File.Open(@"c:\test.bmp",
> FileMode.OpenOrCreate);
> System.Windows.Media.Imaging.JpegBitmapEncoder encoder1 =
> new JpegBitmapEncoder();
> encoder1.Frames.Add(BitmapFrame.Create(rtb));
> encoder1.Save(fs);
>
>
> // BitmapEncoderBmp encoder = new BitmapEncoderBmp();
> // encoder.Frames.Add(BitmapFrame.Create(rtb));
> // encoder.Save(fs);
> fs.Close();


My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Various Errors - winlogon.exe Bad Image, Windows - Bad Image & Window Defender General Discussion
Saving image from web page to documents Vista General
saving zoomed image in photo gallery? Vista music pictures video


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46