3
votes

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:

enter image description here

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:

enter image description here

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:

enter image description here

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.

2
Sorry if I'm not understanding the question, why don't you load the chessboard to a bitmap and then draw your transparent image on it, then you can draw the bitmap anywhere you want?Sertac Akyuz
@SertacAkyuz but if I did that wouldn't the two images becomes one? Example if I drew the Lion on the chessboard then saved it wouldn't the chessboard save with the Lion? I just want to display the chessboard bitmap underneath - not combine it with the actual images.user1175743
Save what? The image in the imagelist? You already have it in the imagelist. I think I still don't understand the question..Sertac Akyuz
@SertacAkyuz I will be needing to save the images from the imagelist to file, so I don't want the chessboard saving with it. The chessboard bitmap is purely for visually representing the images better in the listview.user1175743

2 Answers

4
votes

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;
1
votes

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.