TfrxPictureView and Transparent.
I'm development TfrxPictureView's Transparent.
Why don't work this code?
this code is work in Form.Canvas.
what is ploblem ?
anybody help me.
thanks.
================
procedure StretchBltTransparent(
const DestDC: HDC;
const DestX: Integer;
const DestY: Integer;
const DestWidth: Integer;
const DestHeight: Integer;
const SourceDC: HDC;
const SourceX: Integer;
const SourceY: Integer;
const SourceWidth: Integer;
const SourceHeight: Integer;
const TransparentColor: Windows.TColorRef);
var
bmAndBack, bmAndObject, bmAndMem, bmSave: HBitmap;
bmBackOld, bmObjectOld, bmMemOld, bmSaveOld: HBitmap;
MemDC, BackDC, ObjectDC, SaveDC: HDC;
OldColor: Windows.TColorRef;
begin
BackDC := CreateCompatibleDC(DestDC);
ObjectDC := CreateCompatibleDC(DestDC);
MemDC := CreateCompatibleDC(DestDC);
SaveDC := CreateCompatibleDC(DestDC);
try
bmAndObject := CreateBitmap(SourceWidth, SourceHeight, 1, 1, nil);
bmAndBack := CreateBitmap(SourceWidth, SourceHeight, 1, 1, nil);
bmAndMem := CreateCompatibleBitmap(DestDC, DestWidth, DestHeight);
bmSave := CreateCompatibleBitmap(DestDC, SourceWidth, SourceHeight);
bmBackOld := SelectObject(BackDC, bmAndBack);
bmObjectOld := SelectObject(ObjectDC, bmAndObject);
bmMemOld := SelectObject(MemDC, bmAndMem);
bmSaveOld := SelectObject(SaveDC, bmSave);
try
SetMapMode(SourceDC, GetMapMode(DestDC));
SetMapMode(SaveDC, GetMapMode(DestDC));
{ save the source }
BitBlt(SaveDC, 0, 0, SourceWidth, SourceHeight, SourceDC, SourceX, SourceY, SRCCOPY);
{ Set the background color of the source DC to the color,
contained in the parts of the bitmap that should be transparent }
OldColor := SetBkColor(SaveDC, TransparentColor or $02000000);
{ Create the object mask for the bitmap by performing a BitBlt()
from the source bitmap to a monochrome bitmap }
BitBlt(ObjectDC, 0, 0, SourceWidth, SourceHeight, SaveDC, 0, 0, SRCCOPY);
{ Set the background color of the source DC back to the original }
SetBkColor(SaveDC, OldColor);
{ Create the inverse of the object mask }
BitBlt(BackDC, 0, 0, SourceWidth, SourceHeight, ObjectDC, 0, 0, NOTSRCCOPY);
{ Copy the background of the main DC to the destination }
BitBlt(MemDC, 0, 0, DestWidth, DestHeight, DestDC, DestX, DestY, SRCCOPY);
{ Mask out the places where the bitmap will be placed }
StretchBlt(MemDC, 0, 0, DestWidth, DestHeight, ObjectDC, 0, 0, SourceWidth, SourceHeight, SRCAND);
{ Mask out the transparent colored pixels on the bitmap }
BitBlt(SaveDC, 0, 0, SourceWidth, SourceHeight, BackDC, 0, 0, SRCAND);
{ XOR the bitmap with the background on the destination DC }
StretchBlt(MemDC, 0, 0, DestWidth, DestHeight, SaveDC, 0, 0, SourceWidth, SourceHeight, SRCPAINT);
{ Copy the destination to the screen }
BitBlt(DestDC, DestX, DestY, DestWidth, DestHeight, MemDC, 0, 0, SRCCOPY);
finally
DeleteObject(SelectObject(BackDC, bmBackOld));
DeleteObject(SelectObject(ObjectDC, bmObjectOld));
DeleteObject(SelectObject(MemDC, bmMemOld));
DeleteObject(SelectObject(SaveDC, bmSaveOld));
end;
finally
DeleteDC(MemDC);
DeleteDC(BackDC);
DeleteDC(ObjectDC);
DeleteDC(SaveDC);
end;
end;
Why don't work this code?
this code is work in Form.Canvas.
what is ploblem ?
anybody help me.
thanks.
================
procedure StretchBltTransparent(
const DestDC: HDC;
const DestX: Integer;
const DestY: Integer;
const DestWidth: Integer;
const DestHeight: Integer;
const SourceDC: HDC;
const SourceX: Integer;
const SourceY: Integer;
const SourceWidth: Integer;
const SourceHeight: Integer;
const TransparentColor: Windows.TColorRef);
var
bmAndBack, bmAndObject, bmAndMem, bmSave: HBitmap;
bmBackOld, bmObjectOld, bmMemOld, bmSaveOld: HBitmap;
MemDC, BackDC, ObjectDC, SaveDC: HDC;
OldColor: Windows.TColorRef;
begin
BackDC := CreateCompatibleDC(DestDC);
ObjectDC := CreateCompatibleDC(DestDC);
MemDC := CreateCompatibleDC(DestDC);
SaveDC := CreateCompatibleDC(DestDC);
try
bmAndObject := CreateBitmap(SourceWidth, SourceHeight, 1, 1, nil);
bmAndBack := CreateBitmap(SourceWidth, SourceHeight, 1, 1, nil);
bmAndMem := CreateCompatibleBitmap(DestDC, DestWidth, DestHeight);
bmSave := CreateCompatibleBitmap(DestDC, SourceWidth, SourceHeight);
bmBackOld := SelectObject(BackDC, bmAndBack);
bmObjectOld := SelectObject(ObjectDC, bmAndObject);
bmMemOld := SelectObject(MemDC, bmAndMem);
bmSaveOld := SelectObject(SaveDC, bmSave);
try
SetMapMode(SourceDC, GetMapMode(DestDC));
SetMapMode(SaveDC, GetMapMode(DestDC));
{ save the source }
BitBlt(SaveDC, 0, 0, SourceWidth, SourceHeight, SourceDC, SourceX, SourceY, SRCCOPY);
{ Set the background color of the source DC to the color,
contained in the parts of the bitmap that should be transparent }
OldColor := SetBkColor(SaveDC, TransparentColor or $02000000);
{ Create the object mask for the bitmap by performing a BitBlt()
from the source bitmap to a monochrome bitmap }
BitBlt(ObjectDC, 0, 0, SourceWidth, SourceHeight, SaveDC, 0, 0, SRCCOPY);
{ Set the background color of the source DC back to the original }
SetBkColor(SaveDC, OldColor);
{ Create the inverse of the object mask }
BitBlt(BackDC, 0, 0, SourceWidth, SourceHeight, ObjectDC, 0, 0, NOTSRCCOPY);
{ Copy the background of the main DC to the destination }
BitBlt(MemDC, 0, 0, DestWidth, DestHeight, DestDC, DestX, DestY, SRCCOPY);
{ Mask out the places where the bitmap will be placed }
StretchBlt(MemDC, 0, 0, DestWidth, DestHeight, ObjectDC, 0, 0, SourceWidth, SourceHeight, SRCAND);
{ Mask out the transparent colored pixels on the bitmap }
BitBlt(SaveDC, 0, 0, SourceWidth, SourceHeight, BackDC, 0, 0, SRCAND);
{ XOR the bitmap with the background on the destination DC }
StretchBlt(MemDC, 0, 0, DestWidth, DestHeight, SaveDC, 0, 0, SourceWidth, SourceHeight, SRCPAINT);
{ Copy the destination to the screen }
BitBlt(DestDC, DestX, DestY, DestWidth, DestHeight, MemDC, 0, 0, SRCCOPY);
finally
DeleteObject(SelectObject(BackDC, bmBackOld));
DeleteObject(SelectObject(ObjectDC, bmObjectOld));
DeleteObject(SelectObject(MemDC, bmMemOld));
DeleteObject(SelectObject(SaveDC, bmSaveOld));
end;
finally
DeleteDC(MemDC);
DeleteDC(BackDC);
DeleteDC(ObjectDC);
DeleteDC(SaveDC);
end;
end;