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 ?
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
Related
How can I convert PNG to GIF keeping the transparency?
I would have hoped that using the Assign( ) method would work but it doesn't seem to migrate transparency. In the GIF, it's represented as black.
png:=TPngImage.Create;
try
png.LoadFromFile(sFile);
// comes from file: png.TransparencyMode;
// comes from file: png.Transparent
// didn't help: gif.Transparent:=true;
gif.Assign(png);
// didn't help: gif.Transparent:=true;
gif.SaveToFile('e:\tmp\out.gif');
finally
png.Free;
end;
I haven't found a way to handle this in Delphi...
thanks!
It is possible to transfer an image from a PNG to a GIF. However, I don't recommend that you do so. The GIF format is substantially less capable than PNG. PNG supports RGBA color channels and partial transparency. GIF uses a 256 color palette and no support for partial transparency.
There are many libraries available that will make the best of a bad job and attempt to produce a GIF image that is close to the PNG image, but information will be lost.
The GIF format dates from the late 1980s and time has moved on. It has long since served its purpose. PNG is modern, capable and well supported. If it is possible to do so you should switch from GIF to using PNG.
Seems like CMFCToolBar Allowing only BITMAP Images ( which are of color depth 24 ) to place on Buttons. How to get rid of this limitation. i am neither able to place a PNG nor a bit map with color depth 32 (alpha channel included).
i tried attaching my CPngImage to CBitmap but didn't work.
CPngImage image;
image.Load(AfxGetInstanceHandle(), IDB_PNG1);
bitmap.Attach(image.Detach());
so, finally my doubt can we add a PNG/ Bitmap with alpha channel to CMFCToolBar Button as Image?
Does this work: Icons on menus of MFC Feature Pack classes ? You'd probably have to adapt it a bit to get it to work in your specific case. I'd suggest staying away from using PNG for toolbar icons etc; you can use AlphaConv (google a bit to find it - it moves around a bit it seems) to convert from png to 32 bit bmp.
I need to edit a png image,by giving it border and drop shadow effect. But the final size of the edited image is too high to use for a mobile app .I know that size of jpeg is less compared to that of png.So i convert that image to jpeg and tried to give drop shadow and border effect.But that image is not having transparent background..Is their any other methods to accomplish this using jpeg?
Another option is to try either ImageOptim for losseless compression, or its lossy cousin, ImageAlpha.
ImageOptim tries a series of lossless algorithms to shrink a PNG and selects the smallest result of the bunch. It has taken 25% to 50%+ of quite a few of our images.
ImageAlpha, on the other hand, is lossy and can further crunch the image, with results more like JPEG but without losing Alpha.
You would also do well to disable PNG compression in Xcode as shown here, with additional details here.
What #minitech wanted to say is not about scaling, it's about file compression. jpg and png files usually have some data that could be removed from the file. There are some compression methods to reduce file size (note that is size in kbs, not in scale measurement). Jpg images can reduce file size by reducing image quality, too.
If you want another file type that accepts transparency, there are the gif format, which gives you a smaller file, but have some drawbacks, like a lack of alpha channel (variable transparency). Check this link for more details: http://www.w3.org/QA/Tips/png-gif
There are a couple of online file compressors. If you want to compress png files, you could try using http://tinypng.org/
No, jpeg image wont support transparency.But you can change the white background coming along with jpeg image
How to get a TPicture from a TImageList?
I need to do Image1.Picture:=...TPicture from an image list, to load an image into a TImage.
An image list stores all my PNG images that are transparent.
I tried to use a bitmap (GetBitmap), but what I need is transparency. Unfortunatelly, I have a white background using a bitmap.
Thanks!
The regular TImageList uses bitmaps. Although they can be partially transparent, it is actually just a fake. In Delphi you can draw bitmaps to be transparent by assigning them a single transparent color. That exact color will be drawn a 100% transparent, while the other colors are not. Usually the color is taken from the bottom left corner of the image.
TPicture itself doesn't do anything. It is merely a container for TGraphic descendants. You'll have to find a type of image that can be transparent.
A convenient format is PNG. PNG event supports an alpha channel, which means that every pixel can be assigned a different transparency value.
Fortunately there are TPngImageLists that combine the ease of TImageList with the power of PNG. You can read this article. It is in Dutch, but maybe Google Translate can help you. Or maybe you can find an english resource on this subject. I've used this imagelist and it's great, because you can have actual icons with an alpha channel and still use them with regular toolbars and speedbuttons.
I want to convert some animated PNG (APNG) images to animated GIF. I can successfully convert with a utility I found on the web called apng2gif. Expertly named if I may say. The problem is it does not convert the images with sufficient color depth so the output is a little bit to pixelated and not so smooth relative to the original.
Does anyone know of any other image converters that might convert APNG to GIF with more that 16 bit color depth?
The problem is not with the converter, but with GIF format itself:
http://en.wikipedia.org/wiki/Graphics_Interchange_Format
The format supports up to 8 bits per pixel thus allowing a single image to reference a palette of up to 256 distinct colors.
If you need the GIF to blend better with the background, click on Settings button in apng2gif and then choose the background color you want.