CreateImageFromPicture

Discussions about image processing and document imaging.
Post Reply
DanH
Posts: 11
Joined: Mon Mar 30, 2009 10:13 pm

CreateImageFromPicture

Post by DanH » Sun Nov 29, 2009 12:55 am

Hello,

I'm having trouble in VB6 with CreateImageFromPicture.

Here is some background: I'm working with a vector-based WMF file that is saved in many of our existing user databases. The type of picture has always displayed OK in a standard Image control. Of course, the colors are limited, so I would like to improve the quality with GDPicturePro5.

The problem is the images do not directly display at the highest quality using either CreateImageFromFile or CreateImageFromMetaFile. (They also open as lo-res when I open them with the new version of Paint in Windows 7.) The images sometimes display very nicely after first staging them in an Image control, and then using CreateImageFromPicture. But, some of the images return 0 instead of a handle with this method.

I've attached two picture files in a ZIP folder. RED.wmf returns a handle from CreateImageFromPicture and looks great, but YELLOW.wmf returns 0.

The ZIP flder also contains two example screen shots that illustrate the problem in the application. The Yellow example shows the result of CreateImageFromFile viewing the picture directly, but not at HiRes. The Red example shows the HiRes image displayed after first staging the picture in the Image control. Both examples have the Image version of the picture on the right. The background is transparent.

Any help you can offer will be appreciated.

Regards,
DanH
Attachments
WMF Images.zip
(62.63 KiB) Downloaded 258 times

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: CreateImageFromPicture

Post by Loïc » Sun Nov 29, 2009 6:31 pm

Hi,

To be loaded, GdPicture converts your image as bitmap. If you want to increase image resolution you have to use the CreateImageFromMetaFile with a scale factor.

IE:

Code: Select all

oImaging.CreateImageFromMetaFile("image.wmf", 10)

For your handle issue, I have been able to open both of your files without any problem. Also, you are giving me screenshot of GdViewer controls displaying your two image (this means that you must have a valid image handle).

With best regards,

Loïc

DanH
Posts: 11
Joined: Mon Mar 30, 2009 10:13 pm

Re: CreateImageFromPicture

Post by DanH » Sun Nov 29, 2009 8:04 pm

Hello Loic,

Thanks. CreateImageFromMetaFile works, but a fixed scale factor (such as 10) was sometimes too large. Some WMF files even work best with a value of less than 1.

Right now, I load to an Image staging area, but just to help determine what the scale factor should be. The instances where CreateImageFromPicture did not return a handle from cImage.Picture, the standard picture handle was a negative value.

Here's a snip of my current code. The value of 5000 was chosen by trial and error.

Set fImage.cImage.Picture = LoadPicture(FileName, vbLPCustom, vbLPColor)
l_Height = fImage.cImage.Picture.Height
l_Width = fImage.cImage.Picture.Width
'Example values: l_Height = 796, l_Width = 2113

If l_Height > l_Width Then
l_Imagefactor = 5000 \ l_Height
Else
l_Imagefactor = 5000 \ l_Width
End If

m_Handle = l_Picture.CreateImageFromMetaFile(FileName, l_Imagefactor)

Thanks for your help. You have a great product.

Best regards,
DanH

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest