delphi - How to resize PNG image with Alpha channels using GDI+? -


after looking way resize tpngobject , maintain transparency + alpha channels no avail, i'm trying use gdi+

here code, , seems work fine. down/up scale png. tested on xp far:

uses gdipapi, gdipobj, gdiputil;   procedure tform1.button1click(sender: tobject); var   encoderclsid: tguid;   stat: tstatus;   img, img_out: tgpimage; begin   img := tgpimage.create('in.png'); // 200 x 200     img_out := img.getthumbnailimage(100, 100, nil, nil);   getencoderclsid('image/png', encoderclsid);   img_out.save('out.png', encoderclsid);   img_out.free;   img.free; end; 

my question: using getthumbnailimage correct way of doing this? did not find other method.

i don't think getthumbnailimage method way go because doubt high quality resampled image. in this article can find how rescale image. they're using drawimage method that, same. before set high quality graphics modes high quality output. here example:

procedure tform1.button1click(sender: tobject); var   input: tgpimage;   output: tgpbitmap;   encoder: tguid;   graphics: tgpgraphics; begin   input := tgpimage.create('c:\inputimage.png');   try     // create output bitmap in desired size     output := tgpbitmap.create(100, 100, pixelformat32bppargb);     try       // create graphics object output image       graphics := tgpgraphics.create(output);       try         // set composition mode copy         graphics.setcompositingmode(compositingmodesourcecopy);         // set high quality rendering modes         graphics.setinterpolationmode(interpolationmodehighqualitybicubic);         graphics.setpixeloffsetmode(pixeloffsetmodehighquality);         graphics.setsmoothingmode(smoothingmodehighquality);         // draw input image on output in modified size         graphics.drawimage(input, 0, 0, output.getwidth, output.getheight);               graphics.free;       end;       // encoder , encode output image       if getencoderclsid('image/png', encoder) <> -1         output.save('c:\outputimage.png', encoder)       else         raise exception.create('failed encoder.');           output.free;     end;       input.free;   end; end; 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -