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

DynImage
Author: Message:
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
« Next Oldest Return to Top Next Newest »

Messages In This Thread
DynImage - by davidpolitis on 08-19-2007 at 10:55 AM
RE: DynImage - by Spunky on 08-19-2007 at 11:10 AM
RE: DynImage - by davidpolitis on 08-19-2007 at 11:14 AM
RE: DynImage - by matty on 08-19-2007 at 01:20 PM
RE: DynImage - by davidpolitis on 08-19-2007 at 01:42 PM
RE: DynImage - by matty on 08-19-2007 at 03:02 PM


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