PC Review


Reply
Thread Tools Rate Thread

Create PNG file programmatically from GIF files?

 
 
John Williams
Guest
Posts: n/a
 
      6th Dec 2003
Does anyone know a way of creating a PNG file containing several GIF
files programmatically (using Visual Basic)?

Here's what I do manually in Fireworks. Each Gif is 200 x 200 pixels.

1. Create a new canvas, 400 x 400.
2. Import Gif 1 and position in top left corner (x=0, y=0)
3. Import Gif 2 and position in bottom left corner (x=0, y=200)
4. Import Gif 3 and position in top right corner (x=200, y=0)
5. Import Gif 4 and position in bottom right corner (x=200, y=200)
6. Save Png file.

I would like to do the above within a VB program. A COM object or API
to do the above would be very useful. I've searched for PNG encoders
but they all seem to be for Java apps, and don't offer the precise x,y
positioning I require.

Thanks for any help.
 
Reply With Quote
 
 
 
 
Cor
Guest
Posts: n/a
 
      6th Dec 2003
Hi John,

I think this is the first page to overlook for this.

http://msdn.microsoft.com/library/de...ndDecoders.asp

I hope this was what you where looking for?

Cor
>Does anyone know a way of creating a PNG file containing several GIF
> files programmatically (using Visual Basic)?
>
> Here's what I do manually in Fireworks. Each Gif is 200 x 200 pixels.
>
> 1. Create a new canvas, 400 x 400.
> 2. Import Gif 1 and position in top left corner (x=0, y=0)
> 3. Import Gif 2 and position in bottom left corner (x=0, y=200)
> 4. Import Gif 3 and position in top right corner (x=200, y=0)
> 5. Import Gif 4 and position in bottom right corner (x=200, y=200)
> 6. Save Png file.
>
> I would like to do the above within a VB program. A COM object or API
> to do the above would be very useful. I've searched for PNG encoders
> but they all seem to be for Java apps, and don't offer the precise x,y
> positioning I require.
>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      6th Dec 2003
* (E-Mail Removed) (John Williams) scripsit:
> Does anyone know a way of creating a PNG file containing several GIF
> files programmatically (using Visual Basic)?
>
> Here's what I do manually in Fireworks. Each Gif is 200 x 200 pixels.
>
> 1. Create a new canvas, 400 x 400.
> 2. Import Gif 1 and position in top left corner (x=0, y=0)
> 3. Import Gif 2 and position in bottom left corner (x=0, y=200)
> 4. Import Gif 3 and position in top right corner (x=200, y=0)
> 5. Import Gif 4 and position in bottom right corner (x=200, y=200)
> 6. Save Png file.
>
> I would like to do the above within a VB program. A COM object or API
> to do the above would be very useful. I've searched for PNG encoders
> but they all seem to be for Java apps, and don't offer the precise x,y
> positioning I require.


Untested:

\\\
Dim b As New Bitmap(200, 200, ...)
Dim g As Graphics = Graphics.FromImage(b)
g.DrawImage(...)
g.DrawImage(...)
g.DrawImage(...)
g.DrawImage(...)
g.Dispose()
b.Save(...)
b.Dispose()
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
 
Reply With Quote
 
John Williams
Guest
Posts: n/a
 
      7th Dec 2003
Thank you, both. This does indeed look like what I need. I'll investigate further.
 
Reply With Quote
 
John Williams
Guest
Posts: n/a
 
      16th Dec 2003
(E-Mail Removed) (John Williams) wrote in message news:<(E-Mail Removed)>...
> Thank you, both. This does indeed look like what I need. I'll investigate further.


The following code almost achieves what I want. It creates a 400 x
400 pixel Png file containing 4 Gifs. Each Gif is 200 x 200.

However the resultant Png contains 1 bitmap, whereas the manual
Fireworks procedure creates 4 bitmaps each containing 1 image which
can be manipulated individually. I would like the program to do the
same. Any ideas?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim strGifs(3) As String
Dim i, pos(3, 1) As Integer
Dim oBmpPng As Bitmap
Dim oGraphics As Graphics
Dim oImgTile As Image

'Creates a 400 x 400 pixel Png file containing 4 Gifs. Each
Gif is 200 x 200

strGifs(0) = "TQ09NW04.gif"
strGifs(1) = "TQ09NW08.gif"
strGifs(2) = "TQ09NW24.gif"
strGifs(3) = "TQ09NW28.gif"

pos(0, 0) = 0 : pos(0, 1) = 0
pos(1, 0) = 0 : pos(1, 1) = 200
pos(2, 0) = 200 : pos(2, 1) = 0
pos(3, 0) = 200 : pos(3, 1) = 200

oBmpPng = New Bitmap(400, 400)
oGraphics = Graphics.FromImage(oBmpPng)

For i = 0 To 3
oImgTile = Image.FromFile(strFolder + strGifs(i))
oGraphics.DrawImage(oImgTile, pos(i, 0), pos(i, 1))
Next
oBmpPng.Save(strFolder + "test.png")
oBmpPng.Dispose()

End Sub
 
Reply With Quote
 
John Williams
Guest
Posts: n/a
 
      16th Dec 2003
(E-Mail Removed) (John Williams) wrote in message news:<(E-Mail Removed)>...
> (E-Mail Removed) (John Williams) wrote in message news:<(E-Mail Removed)>...
> > Thank you, both. This does indeed look like what I need. I'll investigate further.

>
> The following code almost achieves what I want. It creates a 400 x
> 400 pixel Png file containing 4 Gifs. Each Gif is 200 x 200.
>
> However the resultant Png contains 1 bitmap, whereas the manual
> Fireworks procedure creates 4 bitmaps each containing 1 image which
> can be manipulated individually. I would like the program to do the
> same. Any ideas?


And I don't think it is anything to do with multiframe images because
the Png file created by Fireworks has a Frame Count of 1 and a Bit
Depth of 32. A Gif file has a Frame count of 1 and a Bit Depth of 8.
 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      16th Dec 2003
Hi John,

I never made a png file, but in the link I gave you I see this code,
I see it nowhere in your code ????

// Initialize GDI+.
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

CLSID encoderClsid;
Status stat;
Image* image = new Image(L"Bird.bmp");

// Get the CLSID of the PNG encoder.
GetEncoderClsid(L"image/png", &encoderClsid);

stat = image->Save(L"Bird.png", &encoderClsid, NULL);

if(stat == Ok)
printf("Bird.png was saved successfully\n");
else
printf("Failure: stat = %d\n", stat);

delete image;
GdiplusShutdown(gdiplusToken);
return 0;

Cor


 
Reply With Quote
 
John Williams
Guest
Posts: n/a
 
      17th Dec 2003
"Cor" <(E-Mail Removed)> wrote in message news:<O#(E-Mail Removed)>...
> Hi John,
>
> I never made a png file, but in the link I gave you I see this code,
> I see it nowhere in your code ????
>

<<snip>>
> // Get the CLSID of the PNG encoder.
> GetEncoderClsid(L"image/png", &encoderClsid);
>
> stat = image->Save(L"Bird.png", &encoderClsid, NULL);


Thanks for your reply, however the example is odd because there is no
Save method for images which uses the Encoder Clsid.

Using 3 of the available Bitmap Save methods, makes no difference to
the output png file. The 3 methods are shown below. Test1.png, 2 and
3 are exactly the same.

Private Sub createPng
Dim strGifs(3) As String
Dim i, pos(3, 1) As Integer
Dim oBmpPng As Bitmap
Dim oGraphics As Graphics
Dim oImgTile As Image
Dim pngFormat As ImageFormat
Dim pngGuid As Guid
Dim pngCodec As ImageCodecInfo
Dim encoderParams As EncoderParameters

pngCodec = GetEncoder("image/png")
pngFormat = ImageFormat.Png

'Creates a 400 x 400 pixel Png file containing 4 Gifs. Each
Gif is 200 x 200

strGifs(0) = "TQ09NW04.gif"
strGifs(1) = "TQ09NW08.gif"
strGifs(2) = "TQ09NW24.gif"
strGifs(3) = "TQ09NW28.gif"

pos(0, 0) = 0 : pos(0, 1) = 0
pos(1, 0) = 0 : pos(1, 1) = 200
pos(2, 0) = 200 : pos(2, 1) = 0
pos(3, 0) = 200 : pos(3, 1) = 200

oBmpPng = New Bitmap(400, 400, PixelFormat.Format32bppRgb)
oGraphics = Graphics.FromImage(oBmpPng)

For i = 0 To 3
oImgTile = Image.FromFile(strFolder + strGifs(i))
oGraphics.DrawImage(oImgTile, pos(i, 0), pos(i, 1))
Next
oBmpPng.Save(strFolder + "test1.png")
oBmpPng.Save(strFolder + "test2.png", pngCodec, encoderParams)
oBmpPng.Save(strFolder + "test3.png", pngFormat)
oBmpPng.Dispose()
oGraphics.Dispose()
oImgTile.Dispose()
End Sub

Private Function GetEncoder(ByVal mimeType As String) As
Imaging.ImageCodecInfo
Dim encoders() As Imaging.ImageCodecInfo =
Imaging.ImageCodecInfo.GetImageEncoders()
Dim i As Integer

For i = 0 To encoders.Length - 1
If encoders(i).MimeType = mimeType Then
Return encoders(i)
End If
Next
End Function
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you programmatically create a file in the App_Data folder? Tony Girgenti Microsoft ADO .NET 6 29th Mar 2007 08:28 PM
Create Blank Excel file Programmatically =?Utf-8?B?U2FyYWg=?= Microsoft Access Form Coding 2 14th Sep 2006 05:47 AM
Create an MDE File Programmatically =?Utf-8?B?ZGFsYmlu?= Microsoft Access VBA Modules 3 26th May 2006 02:07 PM
possible to create a specifications file programmatically? =?Utf-8?B?cmFjaGVs?= Microsoft Access VBA Modules 2 6th Nov 2004 05:22 PM
How to create a MSI file programmatically Thomas Jespersen Microsoft Dot NET 4 13th Oct 2004 11:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:31 AM.