problem with picture format

coldboy
coldboy used Ask the Experts™
on
I want to stretch  picture and save it by BMP format (to add into a Imagelist). If the source picture contain a bitmap, this code work correctly:
Procedure Newpicture(Source:Tpicture;Var DesBMP:Tbitmap;newW,newH:integer);
var i,j:integer;
begin
  DesBMP.width:=newW;
  DesBMP.height:=newH;
  For i:=0 to newW-1 do
    for j:=0 to newH-1 do
      with Source.bitmap do
        DesBMP.canvas.pixels[i,j]:=Canvas.pixel[i*width div newW,j*height div newH];
end;

But the problem come with me if source picture contain a Metal Image or a JPEG Image. If JPEGImage, I can use SaveToClipboardFormat and then use tmpBMP(another Tbitmap).LoadFromClipboardFormat and continue use the code above. But metal image is not! I think, there is simple code (maybe you know but I don't know) can solve my problem. I need yours' helping!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Wim ten BrinkSelf-employed developer

Commented:
What's wrong with:
DesBMP.Canvas.Draw(0,0,SourceImg);

???
Self-employed developer
Commented:
Oh, wait... Stretching... Use StretchDraw() instead... :-)

Author

Commented:
I'm testing your answer...

Author

Commented:
Excellent! But can you show me why I can do by that way? (or how Strechdraw work?)
Wim ten BrinkSelf-employed developer

Commented:
I don't know how it works. I just knows it works. :-) And a bit faster than when you yourself go walking through the bitmap, pixel by pixel, as you tried to do.
I'm not an expert at handling graphical formats but I do know that using the Pixel property will slow down your application enormously. There are faster techniques for this but I just don't know them. (Something with scanlines and things like that.)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial