开发者

Clipping a filmstrip in png format (Delphi 2010)

开发者 https://www.devze.com 2023-03-13 15:18 出处:网络
I have a filmstrip of images in png format like this: I\'d like to know how to clip each of the images and put these images in a TImageList control, always preserving the transparency.

I have a filmstrip of images in png format like this:

Clipping a filmstrip in png format (Delphi 2010)

I'd like to know how to clip each of the images and put these images in a TImageList control, always preserving the transparency.

[EDIT]

Yes, at designtime the trick mentioned by RR开发者_如何学编程UZ works fine, but I wanted to clip the images at runtime, i.e. by loading the filmstrip from resource or file


You must follow these steps:

  • set ColorDepth property to cd32Bit,

  • DrawingStyle to dsTransparent,

  • Height= 48,

  • Width=48,

then load the image and the result will be

Clipping a filmstrip in png format (Delphi 2010)


Just import into the imagelist. It'll complain that it's too big and offer to break it into pieces for you. Works fine for me on D2005.

Another cool tip: I use AWIcons Pro http://www.awicons.com/icon-editor/ to edit icons (nice editor!). It has a feature that can export an icon as an imagelist (.bmp or .png format), thus making the filmstrip out of an icon. This makes it really handy to edit these things in .ico format, with a series of cells all the same size and depth, with each cell varying slightly. Then you export as an imagelist (I use .png) and then Delphi can break them back out into individual cells. Very slick. AWIcons isn't free, but features like this really make it productive.


At runtime, you would have to call TImageList.FileLoad. Except it won't work.

This in turn calls ImageList_LoadImage, with uFlags parameter value including the bit LR_LOADFROMFILE, which causes Windows to load from a file on disk. This underlying functionality only supports TBitmap (BMP) format.

See the nearly-duplicate question. PNG support is a designtime feature that is converting the PNG data into an internal non-PNG and not-exactly-a-BMP-either format, used internally by MS Common Controls library. View your DFM as text, and you will see what your PNG inputs have been turned into. The other answers show you that transparency is preserved, using bitmap-color based transparency.

If you want to keep your data in PNG format, you shouldn't be using a VCL TImageList to store it, because you're going to have to do a conversion from PNG to TBitmap to actually use TImageList.

0

精彩评论

暂无评论...
验证码 换一张
取 消