Forum Replies Created
-
AuthorPosts
-
WhookieParticipant'Support' wrote:
I will try to do it in the v12.03
Hi, I went to the current version (12.12) and found that you have
* Added support of the BkColor property in the TsAlphaImageList component
in 12.03 but it seems as it isn't what I was after.
So I thought a show you a screenshot of what I'm struggling with:
[attachment=8388:imagelist_win.jpg]
The mouse hovers over image 5 (cursor not shown) so this is the only way to see what image is stored there.
What I meant was something like this:
[attachment=8392:imglst_bk.JPG]
I hacked that into your dialog and attached that project too (you need to remove “.pas” though and unpack it).
WhookieParticipant'Support' wrote:What you think about the “PAnsiChar” in this case?
This will work since you are using a pointer type now.
I think you have some backward compatibility issues to take into account (D2007 and lower?) so it's sort of a good compromise (otherwise I would use
Code:Data := PContributorList(PByte(Data) + CSize);instead).
BTW it would be really great to have a selectable background color in the Imagelist window (as I'm working with styles I always have lists with pure white icons and they are invisible)!
WhookieParticipant'Support' wrote:Thank you for the message. I will check and I will try to improve it.
If you have a test-application with error and you can share it, this would be great.
It is a rather big project and I'm on a tight schedule so maybe next month.
To fix my problem do at least the following:
Code:…
Contrib[A].Data := Data;
Data := PContributorList(NativeUInt(Data) + DWord(CSize));
==========WhookieParticipantHi again! I've found a way to do what I wanted. The following code might help someone else and is based on MakeIcon32Rect() from acPng.pas
Code:unit SkinImgLstLoader;interface
Uses
Windows, SysUtils, acPng, acAlphaImageList, Graphics, sConst, sAlphaGraph;Type
TAlphaImageListLoader = Class
private
fGraphic: TPNGGraphic;
fW: Integer;
fH: Integer;
fMaskBitmap: TBitmap;
fFast32Src: TacFast32;
fDstBmp: TBitmap;
fFast32Dst: TacFast32;
fError: Boolean;
function MakeIcon32Rect(SrcX, SrcY: Integer): HICON;
public
constructor Create(const AGraphic: TPNGGraphic; AImgWidth, AImgHeight: Integer); Virtual;
procedure LoadFrom(AX, AY, ACount: Integer; AImgList: TsAlphaImageList; ReplaceImages: Boolean=TRUE);
property Error: Boolean read fError;
End;implementation
Uses
CommCtrl;{ TAlphaImageListLoader }
constructor TAlphaImageListLoader.Create(const AGraphic: TPNGGraphic; AImgWidth, AImgHeight: Integer);
begin
fGraphic := AGraphic;
fW := AImgWidth;
fH := AImgHeight;
end;procedure TAlphaImageListLoader.LoadFrom(AX, AY, ACount: Integer; AImgList: TsAlphaImageList; ReplaceImages: Boolean);
var
iCnt: Integer;
ico: HICON;
begin
fMaskBitmap := TBitmap.Create;
fMaskBitmap.PixelFormat := pf1bit; // doesnt matter, when bmDDB is used (otherwise pf8bit need)
fMaskBitmap.HandleType := bmDDB; // doesnt work when bmDIB (works but needs MaskBitmap.Canvas.Pixels[x,y]:=C.A)?
fMaskBitmap.Width := fW;
fMaskBitmap.Height := fH;
//
fDstBmp := TBitmap.Create;
fDstBmp.PixelFormat := pf32Bit;
fDstBmp.Width := fW;
fDstBmp.Height := fH;
//
fFast32Src := TacFast32.Create;
fFast32Dst := TacFast32.Create;
//
if fFast32Src.Attach(fGraphic) And fFast32Dst.Attach(fDstBmp) then
begin
AImgList.AcBeginUpdate;
if ReplaceImages then //else add images to this list(!)
AImgList.Clear;
AImgList.Width := fW;
AImgList.Height := fH;
fError := FALSE;
//
for iCnt := 0 to ACount – 1 do
begin
ico := MakeIcon32Rect(AX, AY);
if ico 0 then
begin
fError := fError Or (ImageList_AddIcon(AImgList.Handle, Ico) < 0);
DestroyIcon(Ico);
end;
Inc(AX, fW); // LoadFromRow (LoadFromCol = Inc(AY, fH))
end;
AImgList.AcEndUpdate;end;
fFast32Src.Free;
fFast32Dst.Free;
fMaskBitmap.Free;
fDstBmp.Free;
end;function TAlphaImageListLoader.MakeIcon32Rect(SrcX,SrcY: Integer): HICON;
var
IconInfo: TIconInfo;
X, Y : integer;
begin
for y := 0 to fH – 1 do
begin
for x := 0 to fW – 1 do
begin
fFast32Dst[x,y] := fFast32Src[SrcX+x,SrcY+y];
end;
end;IconInfo.fIcon := True;
IconInfo.hbmColor := fDstBmp.Handle;
IconInfo.hbmMask := fMaskBitmap.Handle;Result := CreateIconIndirect(IconInfo);
end;end.
Now one can use that class to load some images from a greater png like:
Code:fImgList := TsAlphaImageList.Create(nil); // create an image list// AGraphic … is a png image loaded from somewhere
// iW, iH … the width/height of one image in the image list
iLoader := TAlphaImageListLoader.Create(AGraphic, iW, iH);
//
// now load some image into the list
// iX, iY … position (upper left corner) of the first image inside the png
// iCn … number of images to load (images have to be horizontally side by side)
// fImgList … img list to add the images to (you could call LoadFrom more than once to have more than one row of images
// using iLoader.LoadFrom(iX, iY, iCn, fImgList, FALSE);)
iLoader.LoadFrom(iX, iY, iCn, fImgList);
iLoader.Free;
// -
AuthorPosts