if (ObjItem.Flipmode <> 0)
then
begin
if Flip
then
begin
Flip := False;
if ObjItem.Flipmode = GD_Reverse
then
begin
Item := gItemFromID(ObjItem.ID);
SelectObject(hDCsrce, ObjItem.Bitmap);
// Create Image from DC using GdipCreateBitmapFromScan0
Img := gBitmapToImage(hDCsrce);
// Flip Image RotateNoneFlipX
GdipImageRotateFlip(Img, 4);
// Delete Old HBitmap
DeleteObject(g_Obj[Item].Bitmap);
// Get ImageSize
GDIP_GetImageSize(Img, ImgW, ImgH);
// CreateCompatibleDC from Source
ImgHDC := CreateCompatibleDC(hDCsrce);
// Create Memory Bitmap with 32 Bit support
hbmpReturn := gCreateDIBSection(hDCsrce, ImgW, ImgH);
// Select Memory Bitmap from DC
SelectObject(ImgHDC, hbmpReturn);
// Delete Old Source DC
DeleteDC(hDCsrce);
if (GdipCreateFromHDC(ImgHDC, Graphics) = OK)
then
begin
// Draw image
GdipDrawImageRect(Graphics, Img, 0, 0, ImgW, ImgH);
// Set the new HBitmap
g_Obj[Item].Bitmap := hbmpReturn;
// Get Bitmap Object
GetObject(hbmpReturn, sizeof(bm), @bm);
pBits := bm.bmBits;
// Remove Transparent Color Black $00000000
for p := 0
to (bm.bmWidth * bm.bmHeight)
do
begin
ColorIs :=
RGB(pBits[2], pBits[1], pBits[0]);
if (ColorIs = $00000000)
then
begin
pBits[3] := 0;
pBits[2] := 255;
pBits[1] := 0;
pBits[0] := 255;
end
else if (ColorIs = 0)
then
begin
if (pBits[3] > 0)
then
pBits[0] := 1;
end
else // Alpha channel for PNG image
begin
AlphaCoef := (255
shl 8)
div pBits[3];
pBits[2] := ((pBits[2] * AlphaCoef)
shr 8);
pBits[1] := ((pBits[1] * AlphaCoef)
shr 8);
pBits[0] := ((pBits[0] * AlphaCoef)
shr 8);
end;
pBits := pBits + 4;
end;
end;
// Cleanup
GdipDeleteGraphics(Graphics);
// Set new Source DC
hDCsrce := ImgHDC;
// Delete old
DeleteDC(ImgHDC);
// Dispose Image
if Img <> 0
then
GdipCheck(GdipDisposeImage(Img));
end;
end;
end;