Saving wmf as gif using GDI+

phil2005
01-04-2005, 11:35 AM
I am trying to save a wmf from the clipboard to a gif file, using Paul's wrapper
I use
SavePicture data.GetData(metaFile), wmfFilepath
Set imgBmp = New cBitmap
imgBmp.LoadFromFile wmfFilepath
codecIndex = imgBmp.ExtensionExists("*.gif")
imgBmp.SaveToFile gifFilepath, imgBmp.EncoderGuid(codecIndex), 0
Kill wmfFilepath

I have two problems

- The wmf file correctly shows a transparent background, but the GIF file has a black background. I have tried
imgBmp.SetTransColor 0 and also 255
but without success

- the Kill wmfFilePath returns Permission Demied

Ideas please!

OnErr0r
01-04-2005, 01:28 PM
I have an example of saving the transparent color of a GIF in the Code Library.

GregDuncan
01-04-2005, 02:10 PM
imgBmp still has a lock on the file. That is why you cant delete it.
Do a set imgBmp = nothing before the kill statement.

phil2005
01-05-2005, 03:26 AM
I have an example of saving the transparent color of a GIF in the Code Library.

I've looked in the Code library at your GDI+ page and done a search on "transparent" but I can't find the sample you are referencing ("GIF" is too short a word for the search engine!)

Sorry, but please can you tell me where to look.

OnErr0r
01-05-2005, 09:47 AM
http://www.visualbasicforum.com/showthread.php?t=92821

Notice that you can bring up the entire GIF palette, once the image has been quantized. The palette entry selected becomes the transparent item when saved. The save code will be most informative.

phil2005
01-06-2005, 08:04 AM
http://www.xtremevbtalk.com/showthread.php?t=92821

Notice that you can bring up the entire GIF palette, once the image has been quantized. The palette entry selected becomes the transparent item when saved. The save code will be most informative.

I have tried this but all the transparent areas of all my gif images show black and the palette entries are all black also.

When I run the Quantise function on any gif I can find, it gives "Error, not 24 bit image".

I am using your tlb dated 24/5/04 and I had to edit the source of the sample to get it to run. I had to change
Private tGuids() As GDIPlus.Guid to Private tGuids() As GDIPlus.clsid (any any .GUID references to CLSID as well) and had to remove the withEvents from Private WithEvents gdip As cBitmap and Public WithEvents gdipGif As cBitmap
.

I then tried a mini-project containing this....
Dim gdipWrapper As cGDIP

Private Sub Form_Load()
Dim imgBMP As New cBitmap
Set gdipWrapper = New cGDIP
Set imgBMP = New cBitmap
imgBMP.LoadFromFile App.Path & "/test.gif"
Set Picture1.Picture = imgBMP.Picture
End Sub

and this also produced black where the gif is transparent.

Any suggestions would be most welcome.

Also, do I understand this right ... if I load a wmf with bitmap.loadfromfile, I need to search its pallete for colors.transparent (&HFFFFFF) and then do bitmap.setranscolor with this index.

OnErr0r
01-06-2005, 08:24 AM
That quantize code was written to quantize a 24 bit BMP down to a smaller number of colors. You can rewrite it to handle GIF, if you want.

Setting .Picture will not maintain transparency, instead, use DrawImage.

phil2005
01-07-2005, 02:10 AM
My problem is, when I do
bipmap.loadfromfile myfile.wmf
bitmap savetofile mygif, gifCodec,0
I loose the transparency in the new gif image

How do I set the gif transparency from the wmf ?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum