2

I have many PNG files with transparency and these PNG fiels seem to be indexed. I would like to :

  • Put 2 identical PNG side to side with a space between both
  • Resize the result with a smooth resize filter (or Mitchell, Linear, Spline or other)
  • Keep transparency and originals colors

Do you have an example to do that ?

Jan Doggen
  • 8,799
  • 13
  • 70
  • 144

1 Answers1

2

This question is related to other PNG resize questions but...

AFAIK, You can't resize an indexed image and keep the original palette. Resizing the image will necessitate the mixing of colors, especially in reducing the image.

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

Community
  • 1
  • 1
Vivian Mills
  • 2,552
  • 14
  • 19
  • Thanks for your response. I've already seen your post and I have retrieved your package on Code Gear but PNG resize doesn't work with my files. I have an error because (I think) my PNG are indexed. Is there an example ? What about the mixing of colors ? Thanks ! – user3195646 May 05 '14 at 19:16
  • If the error is truly due to the image being indexed then the way to fix it would then be to convert it (in memory) to a non-indexed image (either PNG or 32-bit BMP), resize it and then convert it back to an indexed image. When an image is reduced, the original colors are resampled to be presented in the smaller image. it works to fool our eyes into seeing the same image in a smaller size. think about seeing something large and watching it move off into the distance we stop seeing specific individual colors and see a blend of colors, resizing algorithms try to approximate the same thing. – Vivian Mills May 06 '14 at 12:46
  • And do you have an example to do that ? Convert PNG to non-indexed in memory, resize it and convert back ? Thanks ! – user3195646 May 06 '14 at 22:33
  • No because I must combine 2 PNG and I can't draw on PNG canvas so I must use a Bitmap32 in order to draw to – user3195646 May 09 '14 at 20:55