views:

666

answers:

4
+2  Q: 

Resize PNG image

HI! Could you please tell me how to resize a .png image. Or better give an example. I've been searching for the answer for a long time and it seems that nobody knows how to resize a .png image and keep its transparency. :(

A: 

Check this snippet

stacker
I've seen this example, but it creates a png image with a white background and the image is a bit spoiled. I need to keep the transparency and and the quality. Is it possible to do? Thank You!
Actually I need to resize an image with a transparency. The input image should be a png image. The resized output should be drawn on a form's canvas, keeping the transparency. So, may be there is another example when loading .png and converting it to some other format that keeps the transparency and is easily resized. For example, in Windows 7 you are able to resize the items (icons), so can I load a .png and convert it to .ico, for example, and then resize? Of course, if it is easier to resize an icon than a png image!
Ok. Thank you. Then could you show how to resize an icon?
A: 

I must confess that I don't have any experience in programmatically play with png.
Anyway, you will find some libs here. Except the native Delphi PNG support, I think you'll find there all the existing libs (native to delphi of course).

If nothing helps you there, consider playing with ImageMagick if possible...That's the Swiss army knife of the image manipulation and all It can do is feasible in command line

loursonwinny
+1  A: 

You can use Windows Imaging Component (WIC) in Delphi 2010. You can load your PNG image in a TWICImage class, then extract IWICBitmapScaler interface from its handle.

Using IWICBitmapScaler, you can scale down or up the image.

WIC is available on Windows Vista, and Windows 7. For Windows XP, you have to install an update before using it.

vcldeveloper
+3  A: 

The original author of the PNGImage component (the basis of the Delphi native component) had a forum where he, and others, posted code snippets on how to do things using the PNGImage component.

Before the forum was taken down I grabbed a copy of all of the code snippets and placed them on the CodeGear Code Central website.

Most if not all of these work with native PNG images and do maintain the Alpha channel.

Here is the complete list of examples included in the package:

  • Smooth rotates a PNG object
  • Resizes a TPNGObject using a smooth algorithm
  • Slice one PNG into several smaller ones
  • Saves an image as either a bitmap or a png.
  • Sample chunk descendant
  • Read all tEXt-Chunks and write values into a TStrings object
  • Display a message box with information extracted from the PNG File
  • Finds and cuts a block from a PNG image
  • This method converts the png into a jpeg object
  • This method converts the png into a bmp object
  • Overlay one PNG over another
  • This makes the image half transparent
  • Flips a png image vertically and saves back
  • Draws a png image over the desktop

Here is the link: CodeCentral PNG Methods

Ryan J. Mills
THANK YOU VERRRY MUCH!!!