DynImage - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: DynImage (/showthread.php?tid=76875)
DynImage by davidpolitis on 08-19-2007 at 10:55 AM
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.
RE: DynImage by Spunky on 08-19-2007 at 11:10 AM
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
RE: DynImage by davidpolitis on 08-19-2007 at 11:14 AM
Thanks man. If I manage to do it, I'll post the code
Anyway, heres the url for your script: http://shoutbox.menthix.net/showthread.php?tid=68694&page=1
EDIT: Only works for bmp conversion
RE: DynImage by matty on 08-19-2007 at 01:20 PM
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;
}
RE: DynImage by davidpolitis on 08-19-2007 at 01:42 PM
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.
RE: DynImage by matty on 08-19-2007 at 03:02 PM
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.
|