Usage and result of using the IE Delphi Shell

I am developing a listview wrapped on a shell. When trying to extract a shell icon / image ... I try to extract a sketch using IExtractImage if this fails. I am trying to extract the icons using IExtractIcon to get the maximum icon, but IExtractIcon gives strange results. The problem is that I tried to use a method that extracts the icons from the imaginary, but if there is no large icon (256x256), it will display a smaller icon in the upper position of the icon, and this does not look very good. That is why I am trying to use IExtractIcon. But the icons that appear as 256x256 icons in my mosaic extraction method show the sizes of the icons, both 33 large and 16 small. So how to check if a large icon exists (256x256)? If you need more information, I can provide sample code.

if PThumb.Image = nil then begin OleCheck(ShellFolder.ParseDisplayName(0, nil, StringToOleStr(PThumb.Name), Eaten, PIDL, Atribute)); ShellFolder.GetUIObjectOf(0, 1, PIDL, IExtractIcon, nil, XtractIcon); CoTaskMemFree(PIDL); bool:= False; if Assigned(XtractIcon) then begin GetLocationRes := XtractIcon.GetIconLocation(GIL_FORSHELL, @Buf, sizeof(Buf), IIdx, IFlags); if (GetLocationRes = NOERROR) or (GetLocationRes = E_PENDING) then begin Bmp := TBitmap.Create; try OleCheck(XtractIcon.Extract(@Buf, IIdx, LIcon, SIcon, 32 + (16 shl 16))); Done:= False; 

Roy M Clover

+4
source share
1 answer

Take a 256x256 bitmap and just check alpha. Make sure bmp is 32 bit. Any part that has 0 for a pixel value (i.e. BGRA 0,0,0,0 uses TBitmap.Scanline for access) is transparent. You can find the smallest x and the smallest y coordinate, which has a nonzero value and the actual size of your icon. Now this number may be smaller than the size of the icon as it was designed. For example, a 16x16 icon might contain a 2x2 image, which would be a weird design.

But of course, the 8x16 icon is quite possible. Given that the images are always square, take max if the x and y coordinates found (c and the height of the actual image) and round it to the nearest of 16,24,32,48,64,128 or 256. You can be absolutely sure that you will have An icon centered in your bitmap if you crop this size as follows. Use Bmp.Width=sz; Bmp.Height=sz; . Then you can scale it or center it on a standard bitmap (56x56 Γ— 256x256?).

So, even if the windows do not want to give you the correct information, you can bypass this information simply by learning about yourself. This may not be the β€œright” way to do this, but you will know that it will work when you finish, as opposed to viewing MSDN for 4 hours and never finding an answer.

-1
source

Source: https://habr.com/ru/post/1312685/


All Articles