473,770 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 = TheDestinationR ectangle;
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.FromIm age(img))
{
bmp.DrawLine(Pe ns.Black, rc.X, rc.Top, rc.Right, rc.Bottom); //
Line 1
bmp.DrawLine(Pe ns.Black, rc.Right, rc.Top, rc.Left,
rc.Bottom); //Line 2

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

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 2116
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 PrintPageEventA rgs 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...o nly 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
2300
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 some problems I encountered while using them. Please note that, the Regional and Language setting on my machine is using "Metric" measurement system (where the default is "US"). In this case, the measurement unit is "milimeters" and not "inches".
0
2127
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 some problems I encountered while using them. Please note that, the Regional and Language setting on my machine is using "Metric" measurement system (where the default is "US"). In this case, the measurement unit is "milimeters" and not "inches".
1
9591
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 error message "the data area passed to a system call is too small", and nothing else. With SSRS when I try to print the report from the IDE I get the same error, I can load the report up to the report server and view it with IE, then print it from...
5
3351
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 = "P:\2004worksheets\IIS_WS.doc" Set oWord = New Word.Application oWord.Documents.Add (strObjectPath) oWord.PrintOut
5
1975
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 Button1, a printdocument1, a printdialog1, a printpreviewdialog1 and the following code: Private Sub PrintDocument1_PrintPage(ByVal sender as System.Object,
1
5720
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 of a Microsoft book, "Visual Basic,Net Step by Step" in Chapter 18. All but the bottom two subroutines will open a text file, and then allow me to use the above controls, example 1. The bottom two subroutines will print a graphic file, example...
2
1831
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 graphics to printer every second. After 2 minutes it calls Printer.Enddoc and the result is printed out. Printing process is on background and I can use my program normally during this 2 minutes. Now in VB 2005 if I'm right, whole printing...
2
2541
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 locations. But After printing first page it increase paper 3cm vertically/Height so on second
8
5912
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 clients (Internet Explorer). My flash content was originally brought in via the “flash satay” method, but I have since used some server-side magic do deliver one <objecttag
18
11315
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 classes, for each of the checked rows in the GridView. This works fine in the Visual Studio 2005 development environment on localhost. But, when I move the page to the web server, I get the error "Settings to access printer...
0
10232
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8891
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7420
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3974
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2822
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.