Board index » delphi » TimageList.Draw and stretching

TimageList.Draw and stretching

Hello,

I use this code to do a transparent blitting :

Procedure TransStretchDraw(ACanvas:TCanvas;const ARect: TRect; BMP: TBitmap
; TransParentColor:TColor);
var FImageList : TImageList;
    PictureIndex:integer;
begin
Acanvas.brush.style := bsClear;
if BMP.Empty then Exit;
try
FImageList := TImageList.CreateSize(BMP.Width, BMP.Height);
PictureIndex := FImageList.AddMasked(BMP, TransParentColor);
FImageList.Draw(ACanvas, 0, 0, PictureIndex);
finally
    FImageList.Free;
end;

end;

It works fine, but now I would like to do the same with a StretchDraw but
FImageList.StretchDraw doesn't exists, so how can I do this?

thanks

Armindo

 

Re:TimageList.Draw and stretching


Seems like there are only two ways.

a) Do a stretchdraw into a temporary bitmap, then draw the temporary bitmap
into the imagelist
b) Blow off the imagelist and use Timage and your own list instead.

Quote
ADS wrote:
> Hello,

> I use this code to do a transparent blitting :

> Procedure TransStretchDraw(ACanvas:TCanvas;const ARect: TRect; BMP: TBitmap
> ; TransParentColor:TColor);
> var FImageList : TImageList;
>     PictureIndex:integer;
> begin
> Acanvas.brush.style := bsClear;
> if BMP.Empty then Exit;
> try
> FImageList := TImageList.CreateSize(BMP.Width, BMP.Height);
> PictureIndex := FImageList.AddMasked(BMP, TransParentColor);
> FImageList.Draw(ACanvas, 0, 0, PictureIndex);
> finally
>     FImageList.Free;
> end;

> end;

> It works fine, but now I would like to do the same with a StretchDraw but
> FImageList.StretchDraw doesn't exists, so how can I do this?

> thanks

> Armindo

Re:TimageList.Draw and stretching


Quote
> a) Do a stretchdraw into a temporary bitmap, then draw the temporary
bitmap
> into the imagelist

I'm afraid that the stretch will create transition colors.....
For example if I have a red pixel near a White one the stretch will give me
pink color.....

Re:TimageList.Draw and stretching


That is not my experience with StretchDIBits.  It is a very rudimentary
stretching algorithm that simply inserts rows/columns that contain the same
colors as in the bitmap.  You can test this quite easily with a bitmap with
jsut a few colors and hard edges.  You'll see that the color count in the
stretched version (in any photo editor like PaintShop) will be the same.
Quote
ADS wrote:
> > a) Do a stretchdraw into a temporary bitmap, then draw the temporary
> bitmap  into the imagelist

> I'm afraid that the stretch will create transition colors..... For example if
> I have a red pixel near a White one the stretch will give me pink color.....

Re:TimageList.Draw and stretching


Sue,

StretchDIBits is not quite that simple.
How the stretching is performed depends on the specified device context's
stretching mode.
This is explained in the win32 help under SetStretchBltMode.
You use the SetStretchBltMode API to set the stretching mode.

The stretching mode can be one of the following values:
BLACKONWHITE Performs a Boolean AND operation using the color values for the
eliminated and existing pixels. If the bitmap is a monochrome bitmap, this
mode preserves black pixels at the expense of white pixels.
COLORONCOLOR Deletes the pixels. This mode deletes all eliminated lines of
pixels without trying to preserve their information.
HALFTONE Maps pixels from the source rectangle into blocks of pixels in the
destination rectangle. The average color over the destination block of
pixels approximates the color of the source pixels.
WHITEONBLACK Performs a Boolean OR operation using the color values for the
eliminated and existing pixels. If the bitmap is a monochrome bitmap, this
mode preserves white pixels at the expense of black pixels.

The above means that it is essential to use the correct stretching mode,
which depends on the kind of image you want to stretch. Choosing the wrong
stretching mode (or not choosing any at all) for a specific image may result
in a terrible looking stretched image.
--
Finn Tolderlund

"Sue D. Nom" <su...@courthouse.com> skrev i en meddelelse
news:3C6AACA8.F5109F62@courthouse.com...

Quote
> That is not my experience with StretchDIBits.  It is a very rudimentary
> stretching algorithm that simply inserts rows/columns that contain the
same
> colors as in the bitmap.  You can test this quite easily with a bitmap
with
> jsut a few colors and hard edges.  You'll see that the color count in the
> stretched version (in any photo editor like PaintShop) will be the same.

> ADS wrote:

> > > a) Do a stretchdraw into a temporary bitmap, then draw the temporary
> > bitmap  into the imagelist

> > I'm afraid that the stretch will create transition colors..... For
example if
> > I have a red pixel near a White one the stretch will give me pink
color.....

Re:TimageList.Draw and stretching


Right you are!  I had forgotten some really ugly maps I got until I switched to
COLORONCOLOR
Quote
Finn Tolderlund wrote:
> Sue,

> StretchDIBits is not quite that simple.

Re:TimageList.Draw and stretching


Meanwhile, I have to do a stretch in a very large surface (canvas), if I
have to store the stretched bitmap , I won't have enouht memory...

Re:TimageList.Draw and stretching


Why is it so big?

You can tile it up and do the stretches per tile. And store each tile in a
temporary bitmap file.

I assume it is for printing a real photowall, consisting of perhaps 50+  A4
sheets?

Nils
www.abc-view.com

Quote
ADS <Wilda-Rac...@wanadoo.fr> wrote in message news:3c6ba1ad_1@dnews...
> Meanwhile, I have to do a stretch in a very large surface (canvas), if I
> have to store the stretched bitmap , I won't have enouht memory...

Re:TimageList.Draw and stretching


But still even in Color-on-Color or Halftone, there will still be the same
colors. No color mixing is performed to create intermediate colors. Just the
"halftoning" effect works for the eye, but it is the same as newspapers use
with black/white dots to create gray: a dithering technique.

If you really want to create a nice stretched bitmap then it should be some
kind of bicubic filter.. I always like LazcosIII the most. The bicubic
filter is slow, but worth the wait if the result is permanent (like
thumbnails for the web and so on).

If you want to see this in action, then you can look at my app ABC-View
Manager. The viewer window first does a normal stretch to have a result
quickly but then in the background the HQ stretch which will after a few
tenths of a sec replace the crude first step.

The most different are always images with scanned text, or images with
patterns (walls, curtains, luxaflex, etc). That's because the HQ sampling
cancels out the Moire patterns.

Kind regards,

Nils
www.abc-view.com

Sue D. Nom <su...@courthouse.com> wrote in message
news:3C6B0B61.1D5DEEF9@courthouse.com...

Quote
> Right you are!  I had forgotten some really ugly maps I got until I
switched to
> COLORONCOLOR

> Finn Tolderlund wrote:

> > Sue,

> > StretchDIBits is not quite that simple.

Other Threads