473,809 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create PNG file programmaticall y from GIF files?

Does anyone know a way of creating a PNG file containing several GIF
files programmaticall y (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 2834
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 programmaticall y (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.c om (John Williams) scripsit:
Does anyone know a way of creating a PNG file containing several GIF
files programmaticall y (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.FromIm age(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.c om (John Williams) wrote in message news:<a5******* *************** ***@posting.goo gle.com>...
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(B yVal sender As System.Object, ByVal e As
System.EventArg s) 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.g if"
strGifs(1) = "TQ09NW08.g if"
strGifs(2) = "TQ09NW24.g if"
strGifs(3) = "TQ09NW28.g if"

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.FromIm age(oBmpPng)

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

End Sub
Nov 20 '05 #5
jo************* *****@hotmail.c om (John Williams) wrote in message news:<a5******* *************** ***@posting.goo gle.com>...
jo************* *****@hotmail.c om (John Williams) wrote in message news:<a5******* *************** ***@posting.goo gle.com>...
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+.
GdiplusStartupI nput gdiplusStartupI nput;
ULONG_PTR gdiplusToken;
GdiplusStartup( &gdiplusToke n, &gdiplusStartup Input, NULL);

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

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

stat = image->Save(L"Bird.pn g", &encoderClsi d, NULL);

if(stat == Ok)
printf("Bird.pn g 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#******* *******@TK2MSFT NGP10.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", &encoderClsi d);

stat = image->Save(L"Bird.pn g", &encoderClsi d, 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 EncoderParamete rs

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

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

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

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.For mat32bppRgb)
oGraphics = Graphics.FromIm age(oBmpPng)

For i = 0 To 3
oImgTile = Image.FromFile( strFolder + strGifs(i))
oGraphics.DrawI mage(oImgTile, pos(i, 0), pos(i, 1))
Next
oBmpPng.Save(st rFolder + "test1.png" )
oBmpPng.Save(st rFolder + "test2.png" , pngCodec, encoderParams)
oBmpPng.Save(st rFolder + "test3.png" , pngFormat)
oBmpPng.Dispose ()
oGraphics.Dispo se()
oImgTile.Dispos e()
End Sub

Private Function GetEncoder(ByVa l mimeType As String) As
Imaging.ImageCo decInfo
Dim encoders() As Imaging.ImageCo decInfo =
Imaging.ImageCo decInfo.GetImag eEncoders()
Dim i As Integer

For i = 0 To encoders.Length - 1
If encoders(i).Mim eType = 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
13635
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 for a VS.NET setup project. Zip files will not do because these shall be distributed via System Management Server (SMS).
3
7004
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 have a Table, in exactly the same Field format, in each of these 'Weekly' DataBases. I want to set-up a new 'Master' Database, so that I can write one Query to search all the 'Weekly' Databases and produce one new Table in the 'Master' Database...
5
5606
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 that these files will need to be created programmatically. I think saving the DataSets into Access .mdb files is a logical choice, but I'm unable to find any information for creating NEW databases programmatically and I can only find information...
11
3078
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 files on Windows domain network shared drives and also on shared via Samba Unix drives, which is equivalent to writing/reading to the workgroup computer. Please point, if possible, to detailed step by step description of what needs to be done. Thank...
11
8328
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 user. I know that .Net doesn't provide such functionalities therefore I went on MSDN Library and also on Google to look for any solution with no result... I first guessed that using WMI it could be doable (System.Management
7
12684
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
5280
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
43013
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 to a Bound Text Box on a Form, and save the Hyperlink to the underlying Table. The code demos below will do just that: retrieve the Absolute Path of of File from a FileDialog Box, use the Base Name (no extension) as the Display Text for the...
11
2972
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, having hyperlinks to the corresponding full size images. Can anybody point me to locations in MSDN or elsewhere giving the references to attach, the commands & objects for creating or opening the pages and possibly available classes? I have done...
0
9722
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10643
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10391
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4333
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.