Link to home
Start Free TrialLog in
Avatar of coldboy
coldboy

asked on

problem with picture format

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!
Avatar of Wim ten Brink
Wim ten Brink
Flag of Netherlands image

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

???
ASKER CERTIFIED SOLUTION
Avatar of Wim ten Brink
Wim ten Brink
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of coldboy
coldboy

ASKER

I'm testing your answer...
Avatar of coldboy

ASKER

Excellent! But can you show me why I can do by that way? (or how Strechdraw work?)
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.)