473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Printing Problem!

Hi,
Consider a printing scenario where I have to draw the entire page on a
827x1169 (.01 inch) size. Thereafter, the entire bitmap has to be
resized to fill a given Bounds rectangle (keeping the aspect ratio
fixed). To do so, I've just wrote the following code in the PrintPage
event:

Graphics g = e.Graphics;
Rectangle bounds = TheDestinationRectangle;
Rectangle rc = new Rectangle(0, 0, (Int32)(827 * g.DpiX / 100), (Int32)
(1169 * g.DpiY / 100));
using (Bitmap img = new Bitmap(rc.Width, rc.Height))
{
using (Graphics bmp = Graphics.FromImage(img))
{
bmp.DrawLine(Pens.Black, rc.X, rc.Top, rc.Right, rc.Bottom); //
Line 1
bmp.DrawLine(Pens.Black, rc.Right, rc.Top, rc.Left,
rc.Bottom); //Line 2

g.DrawImage(img, bounds, rc, GraphicsUnit.Pixel);
}
}

However, something is really wrong with the above code since both of
those lines (commented out as 1 & 2), are neither anti-aliased nor
smooth. But if I draw the lines this way, everything is perfect:

Graphics g = e.Graphics;
Rectangle rc = new Rectangle(0, 0, 827, 1169);
g.DrawLine(Pens.Black, rc.X, rc.Top, rc.Right, rc.Bottom); //Line 1
g.DrawLine(Pens.Black, rc.Right, rc.Top, rc.Left, rc.Bottom); //Line 2

What am I doing wrong?

Any help would be highly appreciated,

TIA,
Mehdi

Jul 16 '07 #1
1 2087
On Mon, 16 Jul 2007 04:07:49 -0700, mehdi <me***********@gmail.comwrote:
[...]
However, something is really wrong with the above code since both of
those lines (commented out as 1 & 2), are neither anti-aliased nor
smooth. But if I draw the lines this way, everything is perfect:

Graphics g = e.Graphics;
Rectangle rc = new Rectangle(0, 0, 827, 1169);
g.DrawLine(Pens.Black, rc.X, rc.Top, rc.Right, rc.Bottom); //Line 1
g.DrawLine(Pens.Black, rc.Right, rc.Top, rc.Left, rc.Bottom); //Line 2
This has very little to do with printing and everything to do with the
difference between drawing to a bitmap first and drawing directly to an
output device (any output device, whether the screen or a printer).

When you draw into the bitmap, you necessarily limit the resolution of
your lines to the resolution of the bitmap. In this case, that appears to
be 100 dpi (by default the Graphics in the PrintPageEventArgs is already
100 dpi). 100 dpi isn't really all that high resolution, and is usually
much lower than whatever the printer will be printing at.

For example, I've got a couple of ink jet printers here, one is some ten
years old, and for both of them the _draft_ mode is 360 dpi, with puts
approximately 10 times as many pixels into the same area as 100 dpi does..

So, in the code you posted, you're limiting the resolution of the lines to
100 dpi, while when you draw directly to e.Graphics, you use whatever
resolution the printer is printing at (which is almost certainly
considerably higher than 100 dpi).

Thus, jaggies the first way, smooth lines the second.

Note: just because the resolution reported by e.Graphics is 100 dpi, that
doesn't mean that's the actual output resolution. That just happens to be
the coordinate resolution with which your drawing will occur. It's
similar to setting the resolution and pixel measurement when drawing to
the screen; you aren't limited by the resolution with which you specify
drawing coordinates...only the resolution of the output device matters
(unless, of course, you run your graphics primitives through a
lower-resolution bitmap first, as you're doing here).

The moral of the story: if you want the best results, draw directly to the
output device, rather than to a bitmap first. That allows the output
device to take full advantage of the basic graphics primitives you're
using to compose the output.

Pete
Jul 16 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Programatix | last post by:
Hi, I am working on the PrintDocument, PrintDialog, PageSetupDialog and PrintPreviewControl components of Visual Studio .NET 2003. My developement machine is running Windows XP. There are...
0
by: Programatix | last post by:
Hi, I am working on the PrintDocument, PrintDialog, PageSetupDialog and PrintPreviewControl components of Visual Studio .NET 2003. My developement machine is running Windows XP. There are...
1
by: DCraig | last post by:
I'm having problems printing to a line printer from both Crystal Reports and SQL Server reporting services using dotnet. When I try and print a report from an application with Crystal I get the...
5
by: Stefania Scott | last post by:
I am trying to print a word document from Access. The code I've written works well in my computer but does not in the one were it is needed. Here the piece of code: 'doc path strObjectPath =...
5
by: C-Services Holland b.v. | last post by:
Hi all, I've run into a problem trying to print from vb.net (2002) in Windows 98. To test it I've setup a single form with a button and the following code: 'the form has a button called...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
2
by: Teemu | last post by:
I have an application created with VB6 and now I'm converting it to VB 2005. Conversion is not so simple because printing is so much different. In my app I have Timer-component, which is creates...
2
by: Sukh | last post by:
Hi I am stuck with a problem Can anyone help me out from this... I am printing a report on pre-printed continue paper using dot-matrix printer using vb.net. Data is printing on all the...
8
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web...
18
by: Brett | last post by:
I have an ASP.NET page that displays work orders in a GridView. In that GridView is a checkbox column. When the user clicks a "Print" button, I create a report, using the .NET Framework printing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.