![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
| |
| | #1 (permalink) |
| | 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) |
| | 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 | |
| |
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 | |||