473,387 Members | 1,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Create PNG file programmatically from GIF files?

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.
Nov 20 '05 #1
7 2805
Cor
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.

Nov 20 '05 #2
* jo******************@hotmail.com (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>
Nov 20 '05 #3
Thank you, both. This does indeed look like what I need. I'll investigate further.
Nov 20 '05 #4
jo******************@hotmail.com (John Williams) wrote in message news:<a5*************************@posting.google.c om>...
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
Nov 20 '05 #5
jo******************@hotmail.com (John Williams) wrote in message news:<a5*************************@posting.google.c om>...
jo******************@hotmail.com (John Williams) wrote in message news:<a5*************************@posting.google.c om>...
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.
Nov 20 '05 #6
Cor
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
Nov 20 '05 #7
"Cor" <no*@non.com> wrote in message news:<O#**************@TK2MSFTNGP10.phx.gbl>...
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
Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Thomas Jespersen | last post by:
Hello I want to create a MSI file programmatically. Do you know of any third party .NET component which can help me with that? I'm going to use it like a self extracting zip. So it is not...
3
by: G rumpy O ld D uffer | last post by:
This is probably a 'Low-Level' question to all the ACCESS experts but I've only been using ACCESS for a couple of weeks. I've been given 30+ (and counting) separate 'Weekly' Databases which all...
5
by: Jacob | last post by:
Happy New Year! I'm writing a program that will need to store large amounts of data from several DataSets that I create at runtime (for information like email, calendar, etc...). The trick is...
11
by: Andre | last post by:
Hi, I have ASP.NET application running on standalone (not part of the domain) Windows 2003. I use forms authentication for my application. The problem I have is that I need to create and read...
11
by: Amadrias | last post by:
Hi, In one of my current projects, I am willing to create a secure zone such as Acronis does in its application to store some confidential information only accessible to the current machine...
7
by: Supriya | last post by:
Hi All, Is there any way to create .chm file programmatically? Please let me know. Thanks in advance. Supriya
12
by: TS | last post by:
i have a need to possibly enable mutli language support. What benefit do i get by using a resource file instead of a custom xml solution? thanks!
13
ADezii
by: ADezii | last post by:
Recently, there have been several questions and much confusion concerning the Topic of Hyperlinks. Specifically, Users wanted to know how to retrieve a File Name from a FileDialog Box, copy the Name...
11
by: =?Utf-8?B?UGV0ZXIgSw==?= | last post by:
I am working with Visual Studio or alternately with Expression Web. I need to create about 50 aspx pages with about 1200 thumbnali images, typically arranged in three to four groups per page,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.