Page 1 of 1

CreateImageFromPicture

Posted: Sun Nov 29, 2009 12:55 am
by DanH
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

Re: CreateImageFromPicture

Posted: Sun Nov 29, 2009 6:31 pm
by Loïc
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

Re: CreateImageFromPicture

Posted: Sun Nov 29, 2009 8:04 pm
by DanH
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