What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » DynImage

DynImage
Author: Message:
davidpolitis
Full Member
***


Posts: 371
Reputation: 16
Joined: Aug 2006
O.P. Huh?  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
Profile PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
35 / Male / Flag
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:
08-19-2007 11:10 AM
Profile PM Find Quote Report
davidpolitis
Full Member
***


Posts: 371
Reputation: 16
Joined: Aug 2006
O.P. RE: DynImage
Thanks man. If I manage to do it, I'll post the code :P

Anyway, heres the url for your script: http://shoutbox.menthix.net/showthread.php?tid=68694&page=1

EDIT: Only works for bmp conversion :(

This post was edited on 08-19-2007 at 11:41 AM by davidpolitis.
08-19-2007 11:14 AM
Profile PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
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
Profile E-Mail PM Find Quote Report
davidpolitis
Full Member
***


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 :P

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
Profile PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
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
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On