![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 Specs![]() |
| | #2 (permalink) |
| 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 Specs![]() |
![]() |
| 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 |