ich habe jetzt eine methode aus der delphipraxis gefunden, jedoch bin ich mit dem ergebnis wenig zufrieden:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51:
| function IconToBitmap(const IconHandle: HIcon):TBitmap; var IcoInfo: TIconInfo; mask: TBitmap; x, y: word; begin result := nil; if NOT GetIconInfo(IconHandle, IcoInfo) then exit; try try result := TBitmap.Create; result.Handle := IcoInfo.hbmColor; result.PixelFormat := pf32bit;
mask := TBitmap.Create; mask.Handle := IcoInfo.hbmMask; mask.PixelFormat := pf32bit;
for x := 0 to result.Width-1 do for y := 0 to result.Height-1 do pRGBALine(result.Scanline[y])^[x].rgbReserved := NOT pRGBALine(mask.Scanline[y])^[x].rgbRed; except FreeAndNil(result); end; finally if Assigned(mask) then mask.Free; end; end;
function TXIcon.LoadFromFile(aFilename: string): boolean; var ico: HIcon; begin result := false; if Fileexists(aFilename) then begin FFilepath := aFilename; ico := IconFromFile(aFilename, 0); graphic := IconToBitmap(ico); if graphic <> nil then graphic.Transparent := true else graphic := TBitmap.Create; result := true; end; end; |
Delphi-Quelltext
1:
| StretchDraw(temprect, aBar.items[i].graphic); |
Das Ergebnis ist am Anhang zu sehen, einige icons lassen sich net transparent machen, einige funktionieren und einige nur so halb.
wie kann ich das verbessern ?
EDIT: hm so nimmt er auch nur den pixel von unten links und wenn ich den modus umstelle geht das auch net so wirklich
mfg