![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | How to draw to a bitmap and printer? I am working on a graphing module which plots xy-data, e.g. a fever curve, in a 2D chart. In the old times of GDI the low level drawing function got a CDC and a target rectangle: Chart.Draw(CDC* pDC, CRect TargetRect) With this approach I was able to draw to a bitmap and a printer without any effort. pDC just pointed to a memory DC or to a printer DC. Now I want to do the same with WPF. The on-screen drawing is now done by a function which gets a canvas and a rectangle: Chart.Draw(Canvas canvas, Rect targetRect) When drawing to a bitmap or printer I do not only want to copy the window content to the bitmap, but I also want to give the image a new width or height, i.e. the target rectangle changes. So the discussion about "Extracting an image file from the content of a window" does not seem to help. Or does it? Any help appreciated. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: How to draw to a bitmap and printer? fö wrote: > I am working on a graphing module which plots xy-data, e.g. > a fever curve, in a 2D chart. In the old times of GDI the low > level drawing function got a CDC and a target rectangle: > > Chart.Draw(CDC* pDC, CRect TargetRect) > > With this approach I was able to draw to a bitmap and a > printer without any effort. pDC just pointed to a memory DC > or to a printer DC. > > Now I want to do the same with WPF. The on-screen drawing > is now done by a function which gets a canvas and a rectangle: > > Chart.Draw(Canvas canvas, Rect targetRect) > > When drawing to a bitmap or printer I do not only want to copy > the window content to the bitmap, but I also want to give the > image a new width or height, i.e. the target rectangle changes. > So the discussion about "Extracting an image file from the > content of a window" does not seem to help. Or does it? > > Any help appreciated. Hey, The RenderTargetBitmap class does support a Height and Width method so maybe you could try setting these before actually saving the bitmap to the file. It would look something like this (given your graph extends from Visual and has the name foVisual). RenderTargetBitmap bmp = new RenderTargetBitmap((int)foVisual.ActualWidth, (int)foVisual.ActualHeight, 96, // standard WPF ppi setting 96, PixelFormats.Pbgra32); bmp.Render(foVisual); // Now try setting the Width and Length of bmp here... // write the bitmap to a file using (FileStream fs = new FileStream(@"C:\test.png", FileMode.Create)) { PngBitmapEncoder enc = new PngBitmapEncoder(); enc.Frames.Add(BitmapFrame.Create(bmp)); enc.Save(fs); } Give this a shot. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: How to draw to a bitmap and printer? Hi Jason, that works fine! Thanx, fö "Jason Dolinger" wrote: > Jason Dolinger wrote: > > fö wrote: > > > >> I am working on a graphing module which plots xy-data, e.g. a fever > >> curve, in a 2D chart. In the old times of GDI the low level drawing > >> function got a CDC and a target rectangle: > >> Chart.Draw(CDC* pDC, CRect TargetRect) > >> > >> With this approach I was able to draw to a bitmap and a printer > >> without any effort. pDC just pointed to a memory DC or to a printer DC. > >> Now I want to do the same with WPF. The on-screen drawing is now done > >> by a function which gets a canvas and a rectangle: > >> Chart.Draw(Canvas canvas, Rect targetRect) > >> > >> When drawing to a bitmap or printer I do not only want to copy the > >> window content to the bitmap, but I also want to give the image a new > >> width or height, i.e. the target rectangle changes. So the discussion > >> about "Extracting an image file from the content of a window" does not > >> seem to help. Or does it? > >> Any help appreciated. > > > > > > Hey, > > > > The RenderTargetBitmap class does support a Height and Width method so > > maybe you could try setting these before actually saving the bitmap to > > the file. It would look something like this (given your graph extends > > from Visual and has the name foVisual). > > > > RenderTargetBitmap bmp = new RenderTargetBitmap((int)foVisual.ActualWidth, > > > > (int)foVisual.ActualHeight, > > 96, // > > standard WPF ppi setting > > 96, > > > > PixelFormats.Pbgra32); > > > > > > bmp.Render(foVisual); > > > > // Now try setting the Width and Length of bmp here... > > > > // write the bitmap to a file > > using (FileStream fs = new FileStream(@"C:\test.png", FileMode.Create)) > > { > > PngBitmapEncoder enc = new PngBitmapEncoder(); > > enc.Frames.Add(BitmapFrame.Create(bmp)); > > enc.Save(fs); > > } > > > > > > Give this a shot. > > Sorry for the poor code formatting there, I'm not sure why it's all > screwed up... That's how it cut and pasted from VS... > |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Corel draw x13 | Software | |||
| Draw Pad Issues | Windows Live | |||
| Merge one bitmap onto another in vb | .NET General | |||
| bitmap | Vista file management | |||