Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
jaouellette  
#1 Posted : Friday, April 30, 2004 2:08:00 AM(UTC)
jaouellette

Rank: Member

Groups: Member
Joined: 4/30/2004(UTC)
Posts: 16

Is is possible to increase the resolution of an image to get better quality before using the DrawOnHDC to send an image to a printer? I have an image that has a Horizontal Resoloution of 305 and a Vertical Resolution of 305.
Andrew  
#2 Posted : Monday, May 03, 2004 4:19:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 863

Thanks: 2 times
Was thanked: 25 time(s) in 25 post(s)
When you use DrawOnHdc on Printer.hDC, resolution of printer is used. I.e. if your printer is 600 DPI, it will always print the image with 600 dpi regardless to the bitmap resolution. If you want to emulate bitmap resolution on printer's HDC, you should manually resize the image. Take a look into this code sample:

Code:
Private Sub Command1_Click()

    ' Load the file
    Dim objBitmap As New Bitmap
    objBitmap.LoadFromFile "d:\[test files]\Pictures\dog_small.jpg"
    
    ' Specify resolution you want
    objBitmap.HorizontalResolution = 200
    objBitmap.VerticalResolution = 200
       
    ' Obtain resolution of your printer. You can do it using Graphics object of Graphics Mill
    ' Just assign HDC of printer to objGraphics and get HorizontalResolution/VerticalResolution
    ' properties.
    Dim objGraphics As New Graphics
    objGraphics.hDC = Printer.hDC
    
    ' Calculate resolution ratio to resize the bitmap properly
    Dim x As Double, y As Double
    x = objGraphics.HorizontalResolution / objBitmap.HorizontalResolution
    y = objGraphics.VerticalResolution / objBitmap.VerticalResolution
    
    ' Resize the bitmap. To simplify code, retrieve to Resize method percents instead of pixels.
    objBitmap.Unit = UnitPercent
    objBitmap.Transforms.Resize x * 100, y * 100
    
    ' Restore unit back to pixels just in case
    objBitmap.Unit = UnitPixel
    
    ' Print the image
    Printer.Print " "
    objBitmap.DrawOnHdc Printer.hDC
    Printer.EndDoc
    
End Sub


Note, you will not increase the quality by resizing the bitmap. This method can be used to manage the physical size of the image you print, not the quality. To increase quality, you should change printer resolution. And of course, the image should have high resolution initially.

Please let me know if you have any problems with it.

Edited by user Monday, December 24, 2007 5:54:14 PM(UTC)  | Reason: Not specified

jaouellette  
#3 Posted : Tuesday, May 04, 2004 9:06:00 PM(UTC)
jaouellette

Rank: Member

Groups: Member
Joined: 4/30/2004(UTC)
Posts: 16

Thank you for the response! I have attempted to test the example that you gave me and now when I execute the following code:


Code:
objBitmap.DrawOnHDC Printer.hdc



I get the following error:


Code:
run-time error -4104 (ffffeff8)

Method DrawOnHdc failed.  Unable to create color transform message.  



Any idea on what I might have done wrong?


Thanks!
Jason...

Edited by user Monday, December 24, 2007 5:54:29 PM(UTC)  | Reason: Not specified

jaouellette  
#4 Posted : Wednesday, May 05, 2004 1:43:00 AM(UTC)
jaouellette

Rank: Member

Groups: Member
Joined: 4/30/2004(UTC)
Posts: 16

I found the answer to my question. I need to add the following line:


Code:
objBitmap.Data.ConvertToCmyk



This resolved the error.

Thank you!

Edited by user Monday, December 24, 2007 5:54:41 PM(UTC)  | Reason: Not specified

jaouellette  
#5 Posted : Wednesday, May 05, 2004 9:54:00 AM(UTC)
jaouellette

Rank: Member

Groups: Member
Joined: 4/30/2004(UTC)
Posts: 16

One more question... I am printing these images on to badges that are 855 x 1339 pixels and when I use the:

Code:
newWidth = 211
objBitmap.Transforms.Resize newWidth, , InterpolationModeHighQuality


and then:

Code:
    Printer.Print ""
    Printer.ScaleMode = vbPixel
    objBitmap.Data.ConvertToCmyk True
    objBitmap.DrawOnHDC Printer.hDC
    Printer.EndDoc


the image that prints is much smaller than the 211 x ? pixels that the image was resized to. Can you offer me any incite on how to properly adjust the size of the image as well as an example of how to keep the ratio of the original image so that it is not distorted?

Thank you!
Jason... ;)

Edited by user Monday, December 24, 2007 5:54:58 PM(UTC)  | Reason: Not specified

Andrew  
#6 Posted : Wednesday, May 05, 2004 1:01:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 863

Thanks: 2 times
Was thanked: 25 time(s) in 25 post(s)
Jason,

> the image that prints is much smaller than the 211 x ? pixels that the image was resized to.

The problem is that pixels is a device-dependent unit. It means that you cannot say what length of some number of pixels should be. It depends on the device where you print the image and the device resolution. Resolution is a value which specifies how much pixels are contained in some physical length unit (as usual in one inch). For example, if you print 211 pixel image with 300 DPI, you will get 0.7 inches. If you print with 600 DPI, width will be 0.3 inches. When you browse the image on the monitor, as usual it has 96 DPI, so it will seem you to be 2.1 inches.

To avoid this uncertainty, you should use device-independent units. The most wide-spread device-independent units are points (1/72). These units do not depend on the device resolution. 211 points is always about 3 inches regardless to the DPI.

Please let me know if something is unclear.

> as well as an example of how to keep the ratio of the original image so that it is not distorted?

When you omit one of parameters in Resize method, it should proportionally resize the image and keep the ratio. Do you have problems with it?
jaouellette  
#7 Posted : Monday, May 10, 2004 2:31:00 AM(UTC)
jaouellette

Rank: Member

Groups: Member
Joined: 4/30/2004(UTC)
Posts: 16

Andrew,
Thank your help. Te conversion to Points resolved the problem!

Jason... :D
Andrew  
#8 Posted : Monday, May 10, 2004 2:24:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 863

Thanks: 2 times
Was thanked: 25 time(s) in 25 post(s)
Glad to know that you get it working. Feel free to post again if you get any other questions.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.