How to work with non-visible TImage32 - delphi

I try to make use of a TImage32 to combine several layers with positions and transparency etc. So I create in runtime a TImage32, set parent to nil, load from file a bitmap and load from file a layer on top of that bitmap. Now I want to save the result, but I seem to be unable to find where the actual result is. If I do the same with creating the TImage32 in designtime, make it visible, the result of the combined bitmaps is in the Buffer field of TImage32, and I can save the result using Image32.Buffer.SaveToFile('test.bmp'). If the component is not visible, the Buffer is an empty bitmap and the combined bitmap seem to be not created.
Can someone shed light on this? How do I combine bitmaps with GR32, save them, but with invisible components?
Thanks a lot!
Willem

You don't need to use visual controls like TImage.
The library you're using graphics32 has all the methods you need.
Use TBitmap32: The Bitmap can be displayed and scaled using its DrawMode, MasterAlpha and StretchFilter properties.
You simply use the MyBitmap.LoadFromFile method to get it.
I suggest you then store your bitmaps in a TObjectList.
Combine them using TBitmap32.Draw{To}, note that you can use the DrawMode to modify the behavior of Draw.
And use the SaveToFile method as usual when done manipulating the bitmap.

Related

What is equivalent of Canvas.Pixels[X,Y] in Firemonkey?

In VCL we can get the color of specific pixel from Canvas or bitmap like this:
Canvas.Pixels[X,Y]
but we have not such a thing for canvas and bitmap in firemonkey components. how can we read or write a specific point on a canvas in FMX?
I presume that you are working with a bitmap, if you wish to operate on pixel data. In which case you use the Map method of the TBitmap class. More details here:
http://www.fmxexpress.com/get-direct-pixel-access-to-bitmaps-in-delphi-xe5-firemonkey-on-android-and-ios/
http://members.adug.org.au/2012/10/05/read-write-image-bitmap-pixels-in-delphi-xe3/
http://docwiki.embarcadero.com/CodeExamples/en/FMX.AlphaColorToPixel_(Delphi)

How can animate gif loaded in TImageList?

I want to know how is it possible to animate gif image that is put in TImageList.
I know that if we could access the graphic of each images in TImageList it may be possible cast the graphic of the picture to TGIFImage and set Animate property to true. but the problem is how can we access the image that is loaded in TImageList and cast it to TGIFImage and set that animate property?
EDIT:
How we can have animated gif in TTreeView?
As David Heffernan answered TImageList is not appropriate for saving gif images. but the purpose of this question was to have an animated gif in a treeview. By the suggestion of Remy-lebeau I wrote a unit for that. In this unit I defined two classes. first TGifImageRefrence that uses a TImagelist as its property and must be assigned and has a procedure that add gif image to this imagelist. each frame will be saved as single image in Imagelist and frames' indexes and animationspeed will be saved.
The Second class is TGifNode that its purpose is to be a node in TreeView. It contains a timer an accept a TGifImageRefrence as it's property. you can inherit a class for your own node for your treeview from this class. I write an example using this unit and put them together and you can download it from http://loghman.ir/MySource/GifInTreeView.zip
A TImageList stores a list of equally sized static images. It's not appropriate for hosting an animated GIF. You could unpack all the images from the animated GIF and put them in the images list. And then reconstruct them later for animation. That would seem pointless. You should use TGIFImage for animating a GIF.

Changing WMF color

i have been trying to change colors on a wmf canvas in Delphi, with usual images i just run a scanline or by running a loop on each X and Y pixel and give it a new color code, but with MetaCanvas this method doesnt work, maybe because it is not actually an image but instead a list of GDI functions. I read somewhere that i would need to decompile and recompile the metafile for changing color properties in it. But i dont have a clue how i will do it or if there is another easy way for it.
If anyone can point me in the right direction.
Thanks
There is a mechanism for you to modify the contents of a meta file.
Call EnumEnhMetaFile passing a callback function, EnhMetaFileProc. The callback function is called for each record in the metafile. You can take a copy of this record, modify it, and then pass it to PlayEnhMetaFileRecord.
So, you could look for records that specified colours, and make whatever modifications you need.

Display secondary underlying image on a Imagelist?

I have a Image list assigned to a listview to display transparent images.
There is a slight issue with this regarding some transparent images that are added, and that is they are sometimes hard to see/find in the listview.
See this example image:
You will notice that the images (noticeably the mouse) is barely viewable, infact if a empty image was added you would not even see it, the number captions come to the rescue here to show there is something actually there.
But I would like to make the images visually easier to see. I thought maybe having another image underneath the transparent images would work - of course though it could not affect the actual image.
So with that in mind, I made a bitmap of a chessboard grid:
I feel this would be the most suitable way of representing transparent areas of the images just like Paint.NET etc does.
To further illustrate this example I have modified the original image to show how it would look, if we had the chessboard bitmap as the underlay image:
Having the chessboard there would indicate there is a list item there in the first place, and the bitmap of the chessboard grid could be darker or an altogether different kind of image. As I said earlier if there was no image you would see nothing at all, so better to show an empty chess grid or other bitmap than nothing.
So, how can I display a second image underneath the original images using a imagelist to give a result similar to the example above? The underneath image could be anything - just another loaded bitmap for example.
If you store the chessboard as the first image (with index 0) and make the overlay image from the current image in the OnGetImageIndex event handler, it will do what you want to. However I'm not sure how efficient is to make the overlay image every time the event is fired.
procedure TForm1.ListView1GetImageIndex(Sender: TObject; Item: TListItem);
begin
// make the overlay (with overlay index 1) from the
// image with index Item.Index + 1
ImageList1.Overlay(Item.Index + 1, 1);
// use the first image from the list as a background
Item.ImageIndex := 0;
// and assign just created overlay index for overlay
Item.OverlayIndex := 1;
end;
I seems that what you need is a TImageList with extra capabilities.
As a starting point, I suggests you to consider TImageListEx described in the book Inside Delphi 2006
Excerpt:
The TImageListEx component is a TImageList descendant that can use the
images from another image list to generate disabled images, which can
be used on toolbars and other user interface elements.
The TImageListEx component is a TImageList descendant that can use the
images from another image list to generate disabled images, which can
be used on toolbars and other user interface elements.
There are several benefits of the TImageListEx component:
It eliminates the need for creating disabled glyphs.
It eliminates the need for adding the disabled glyphs to an additional TImageList component at design time.
It can drastically reduce the size of the .dfm file and of the entire application, especially in large applications that use a lot of
glyphs.
It's extremely fast, taking only milliseconds to disable all images in an image list, even when there are number of images.
It's extremely lightweight. (If you add it to an application that already uses the standard TImageList component, it won't increase the
size of the executable at all, and if you add it to an application
that doesn't use the standard TImageList component, the overhead is
only 2 KB.)
It's far from your requirements but yet detailed enough to show how to extend TImageList.

Transparency in TImage

When a new TImage is created it is transparent. After drawing objects to this image I would like to clear them. Note that I need to keep the image transparent as the TImage is being used as an overlay to another image.
Some sort of "clear" function for the TImage would be best. I think I'm missing something simple here, I just could not find any clear function within the TImage menu.
You're not really meant to draw things on a TImage control. You're meant to assign its Picture property and leave it alone. In fact, when you draw on a TImage, you're either drawing transiently by drawing on its Canvas property, or you're modifying the underlying Picture object by drawing on its canvas.
To clear a TImage, simply unassign the Picture property.
Image.Picture := nil;
To draw transient images — something you'll need to repaint whenever the window gets obscured and revealed — use a TPaintBox.

Resources