DynImage |
Author: |
Message: |
davidpolitis
Full Member
![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif)
Posts: 371 Reputation: 16
Joined: Aug 2006
|
O.P. DynImage
I've been trying for a while now to use DynImage to convert image formats to png and I cannot manage to do it, the image allways comes out just plain old white.
Could someone please supply some sample code for jpg to png.
Thanks,
David.
This post was edited on 08-19-2007 at 11:01 AM by davidpolitis.
|
|
08-19-2007 10:55 AM |
|
![](images/pixel.gif) |
Spunky
Former Super Mod
![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif)
![Avatar](http://i39.tinypic.com/345jujo.png)
Posts: 3656 Reputation: 61
36 / / ![United Kingdom Flag](images/flags/gb.png)
Joined: Aug 2006
|
RE: DynImage
It can't be done with DynImage IIRC... It needs a seperate DLL or you could use some windows APIs... Check out my ChangeMe! script thats on the forum somewhere as I think it also included the second DLL for file conversion
<Eljay> "Problems encountered: shit blew up" ![:zippy:](images/smilies/zippy.gif)
|
|
08-19-2007 11:10 AM |
|
![](images/pixel.gif) |
davidpolitis
Full Member
![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif)
Posts: 371 Reputation: 16
Joined: Aug 2006
|
|
08-19-2007 11:14 AM |
|
![](images/pixel.gif) |
matty
Scripting Guru
![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif)
Posts: 8328 Reputation: 109
39 / / ![Canada Flag](images/flags/ca.png)
Joined: Dec 2002
Status: Away
|
RE: DynImage
Welcome to the wonderful world of Gdip
code: var sGpStatus = new Array('[Ok]', '[GenericError]', '[InvalidParameter]', '[OutOfMemory]', '[ObjectBusy]', '[InsufficientBuffer]', '[NotImplemented]', '[Win32Error]', '[WrongState]', '[Aborted]', '[FileNotFound]', '[ValueOverflow ]', '[AccessDenied]', '[UnknownImageFormat]', '[FontFamilyNotFound]', '[FontStyleNotFound]', '[NotTrueTypeFont]', '[UnsupportedGdiplusVersion]', '[GdiplusNotInitialized]', '[PropertyNotFound]', '[PropertyNotSupported]');
function OnEvent_Initialize(MessengerStart){
GdipConvertImage('c:\\myimage.jpg', 'c:\\myimage.png');
}
/*
Name: GdipConvertImage
Purpose: Converts an image of any format to PNG
Parameters: sImgIn - The path to the original image
sImgOut - The path to the file to output
Return: True if function succeeds / False if it fails
*/
function GdipConvertImage (sImgIn /* InputFile */, sImgOut /* Output File */) {
var ret;
var GdipToken = Interop.Allocate(4);
var nImgPtr = Interop.Allocate(4);
var GdipStartupInput = Interop.Allocate(16);
GdipStartupInput.WriteDWORD(0, 1);
Interop.Call('gdiplus', 'GdiplusStartup', GdipToken, GdipStartupInput, 0);
if (GdipToken.ReadDWORD(0) !== 0 /* Loaded Properly */) {
Interop.Call('gdiplus', 'GdipLoadImageFromFile', sImgIn, nImgPtr);
if (nImgPtr.ReadDWORD(0) !== 0 /* Check to see if the image was loaded by Gdip */) {
var ImageFormat = Interop.Allocate(16);
Interop.Call('ole32', 'CLSIDFromString', '{557CF406-1A04-11D3-9A73-0000F81EF32E}', ImageFormat);
var EncoderParameters = Interop.Allocate(32);
with (EncoderParameters){
WriteDWORD (0, 1);
WriteDWORD (20, 1);
WriteDWORD (24, 4);
}
Interop.Call('ole32', 'CLSIDFromString', '{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}', EncoderParameters.DataPtr+4);
ret = Interop.Call('gdiplus', 'GdipSaveImageToFile', nImgPtr.ReadDWORD(0), sImgOut, ImageFormat, EncoderParameters);
Debug.Trace('Convert of '+sImgIn+' to '+sImgOut+(ret === 0 ? ' successful.' : ' failed! (Error Code : '+sGpStatus[ret]+')'));
Interop.Call('gdiplus', 'GdipDisposeImage', nImgPtr.ReadDWORD(0));
}
}
Interop.Call('gdiplus', 'GdiplusShutdown', GdipToken.ReadDWORD(0));
return ret === 0;
}
This post was edited on 08-19-2007 at 01:27 PM by matty.
|
|
08-19-2007 01:20 PM |
|
![](images/pixel.gif) |
davidpolitis
Full Member
![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif)
Posts: 371 Reputation: 16
Joined: Aug 2006
|
O.P. RE: DynImage
matty, you are one seriously extreme coder XD
Thanks once again, keep up the good work
One more thing, would it be possible for me to easily check the file format of an image besides using lastIndexOf etc.
This post was edited on 08-19-2007 at 01:49 PM by davidpolitis.
|
|
08-19-2007 01:42 PM |
|
![](images/pixel.gif) |
matty
Scripting Guru
![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif)
Posts: 8328 Reputation: 109
39 / / ![Canada Flag](images/flags/ca.png)
Joined: Dec 2002
Status: Away
|
RE: DynImage
There is yes,
I don't however have a way of testing it currently so I cannot provide you with code to use it (I am at work). However when I get home I will do it unless someone else does already.
|
|
08-19-2007 03:02 PM |
|
![](images/pixel.gif) |
|
|