Board index » delphi » Transparent StretchDraw Enhancement...

Transparent StretchDraw Enhancement...

Greetings,

  I was wondering if anyone has run into problems using StretchDraw to
transfer 256 color images to a > 256 color display.   Personally I had a
bit of trouble with the color in the resulting screen image.  I'm
working on NT4/SP4.   Note that the TransparentStretchBlt uses an API
call if the machine is NT, so the problem only seemed to manifest on 95
/ 98.

My transparent draws appeared to work 99% of the time, but when
particular transparent colors were used, some of the destination pixels
would get the wrong colour.

The workaround was to modify the Delphi VCL unit Graphics.pas in the
TransparentStretchBlt function,

  function TransparentStretchBlt(DstDC: HDC; DstX, DstY, DstW, DstH:
Integer;
   <<snip>>
    try
      MemDC := GDICheck(CreateCompatibleDC(0));
      try
        MemBmp := GDICheck(CreateCompatibleBitmap(SrcDC, SrcW, SrcH));

I changed the above to :

      MemDC := GDICheck(CreateCompatibleDC(DstDC));
      try
        MemBmp := GDICheck(CreateCompatibleBitmap(DstDC, SrcW, SrcH));

and all my problems went away!

Any comments welcome

Laurie  :-)

 

Re:Transparent StretchDraw Enhancement...


I was having a lot of problems with TrasparentStretchBlt because it was
only coming out transparennt some of the time. I could do it 5 times and
3 would be transparent. I finally realized if I just make the rop a
SRCAND it did the transpoarent BLT a faster and is always accurate.

Quote
Laurie wrote:
> Greetings,

>   I was wondering if anyone has run into problems using StretchDraw to
> transfer 256 color images to a > 256 color display.   Personally I had
> a bit of trouble with the color in the resulting screen image.  I'm
> working on NT4/SP4.   Note that the TransparentStretchBlt uses an API
> call if the machine is NT, so the problem only seemed to manifest on
> 95 / 98.

> My transparent draws appeared to work 99% of the time, but when
> particular transparent colors were used, some of the destination
> pixels would get the wrong colour.

> The workaround was to modify the Delphi VCL unit Graphics.pas in the
> TransparentStretchBlt function,

>   function TransparentStretchBlt(DstDC: HDC; DstX, DstY, DstW, DstH:
> Integer;
>    <<snip>>
>     try
>       MemDC := GDICheck(CreateCompatibleDC(0));
>       try
>         MemBmp := GDICheck(CreateCompatibleBitmap(SrcDC, SrcW, SrcH));

> I changed the above to :

>       MemDC := GDICheck(CreateCompatibleDC(DstDC));
>       try
>         MemBmp := GDICheck(CreateCompatibleBitmap(DstDC, SrcW, SrcH));

> and all my problems went away!

> Any comments welcome

> Laurie  :-)

Re:Transparent StretchDraw Enhancement...


Hiya Sim,

Quote
> I was having a lot of problems with TrasparentStretchBlt because it
> was only coming out transparennt some of the time. I could do it 5
> times and 3 would be transparent. I finally realized if I just make
> the rop a SRCAND it did the transpoarent BLT a faster and is always
> accurate.

Which bit of code did you change to a SRCAND?

Thanks,  Laurie

Quote
>>   I was wondering if anyone has run into problems using StretchDraw
>> to transfer 256 color images to a > 256 color display.   Personally
>> I had a bit of trouble with the color in the resulting screen
>> image.  I'm working on NT4/SP4.   Note that the
>> TransparentStretchBlt uses an API call if the machine is NT, so the
>> problem only seemed to manifest on 95 / 98.

>> My transparent draws appeared to work 99% of the time, but when
>> particular transparent colors were used, some of the destination
>> pixels would get the wrong colour.

>> The workaround was to modify the Delphi VCL unit Graphics.pas in the
>> TransparentStretchBlt function,

>>   function TransparentStretchBlt(DstDC: HDC; DstX, DstY, DstW, DstH:
>> Integer;
>>    <<snip>>
>>     try
>>       MemDC := GDICheck(CreateCompatibleDC(0));
>>       try
>>         MemBmp := GDICheck(CreateCompatibleBitmap(SrcDC, SrcW,
>> SrcH));

>> I changed the above to :

>>       MemDC := GDICheck(CreateCompatibleDC(DstDC));
>>       try
>>         MemBmp := GDICheck(CreateCompatibleBitmap(DstDC, SrcW,
>> SrcH));

>> and all my problems went away!

>> Any comments welcome

>> Laurie  :-)

Other Threads