Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

saving image from inkcanvas

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 03-08-2006   #1 (permalink)
madhur
Guest


 

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]
Guest


 

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
Closed Thread
Update your Vista Drivers Update Your Drivers Now!!

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Acronis True Image recovery of Vista Image mrh981 Vista General 1 07-01-2008 09:57 PM
Saving image from web page to documents Heather Vista General 5 08-17-2007 10:50 AM
InkCanvas Simon Avalon 0 06-28-2007 06:48 PM
saving zoomed image in photo gallery? ecm@emokotoff.com Vista music pictures video 1 03-19-2007 12:22 AM
Text content on InkCanvas Raghavendra Avalon 0 01-22-2007 01:33 AM


Vistax64.com 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 2005-2008

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 47 48 49 50 51