Printing a rectangle with exact sizes...
-
Hi all! I have to print a bar with its exact sizes. I used this code to generate a bar:
PrinterSettings ps = new PrinterSettings(); Graphics g = ps.CreateMeasurementGraphics(); IntPtr pHdc = g.GetHdc(); mf = new Metafile(pHdc, EmfType.EmfOnly); g.ReleaseHdc(pHdc); g.Dispose(); g = Graphics.FromImage(mf); g.PageUnit = GraphicsUnit.Millimeter; g.PageScale = 1; Brush b = Brushes.Black; g.FillRectangle(b, 0, 0, 2, 30); float dpix = g.DpiX; float dpiy = g.DpiY; g.Dispose(); Bitmap bm = new Bitmap(mf, (int)(mf.Width / mf.HorizontalResolution * dpix), (int)(mf.Height / mf.VerticalResolution * dpiy)); mf.Dispose();
Well, when I print the bm Bitmap I obtain a big bar on my page: it isn't 2x30 mm wide, but 12x188 mm wide! Can you help me? Thanks in advantage -
Hi all! I have to print a bar with its exact sizes. I used this code to generate a bar:
PrinterSettings ps = new PrinterSettings(); Graphics g = ps.CreateMeasurementGraphics(); IntPtr pHdc = g.GetHdc(); mf = new Metafile(pHdc, EmfType.EmfOnly); g.ReleaseHdc(pHdc); g.Dispose(); g = Graphics.FromImage(mf); g.PageUnit = GraphicsUnit.Millimeter; g.PageScale = 1; Brush b = Brushes.Black; g.FillRectangle(b, 0, 0, 2, 30); float dpix = g.DpiX; float dpiy = g.DpiY; g.Dispose(); Bitmap bm = new Bitmap(mf, (int)(mf.Width / mf.HorizontalResolution * dpix), (int)(mf.Height / mf.VerticalResolution * dpiy)); mf.Dispose();
Well, when I print the bm Bitmap I obtain a big bar on my page: it isn't 2x30 mm wide, but 12x188 mm wide! Can you help me? Thanks in advantageHi, "mm" is not the standard for computers! Neither for the postscript i guess. Secondly, it differs for different disply resolution. For Example: Screen Res: 1024x768, Diagonal Size: 19", Pixel size: 0.377mm Screen Res: 800x600, Diagonal Size: 17", Pixel size: 0.4318mm Screen Res: 640x480, Diagonal Size: 15", Pixel size: 0.4763mm (taken from ^ [^]) So you better calculate about your display resolution. Hope that helps! Regards, Adeel
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.
-
Hi, "mm" is not the standard for computers! Neither for the postscript i guess. Secondly, it differs for different disply resolution. For Example: Screen Res: 1024x768, Diagonal Size: 19", Pixel size: 0.377mm Screen Res: 800x600, Diagonal Size: 17", Pixel size: 0.4318mm Screen Res: 640x480, Diagonal Size: 15", Pixel size: 0.4763mm (taken from ^ [^]) So you better calculate about your display resolution. Hope that helps! Regards, Adeel
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.