Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-11

Loading file into TImageList does not properly scale

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Matt Shaffer

Hello, the code below is how I load and convert PNG files into BMPs, add them to a TImageList, and then add them to a TListView. The problem I'm having is that I cannot get the little bugger to scale to 96x96; other than that the code works. I would imagine that setting the timage's stretch property to true ought to scale the image to 96x96, but that was not the case.

lsTextures: TListView;
imgTextures: TImageList;
procedure TForm1.MenuItem15Click(Sender: TObject);
var
   bmp: TBitmap;
   img: TImage;
   itm: TListItem;
begin
     bmp := TBitmap.Create;
     img := TImage.Create(nil);
     try
        lsTextures.BeginUpdate;
        img.Stretch := true;
        img.Width := 96;
        img.Height := 96;
        bmp.Width := 96;
        bmp.Height := 96;
        img.Picture.LoadFromFile('screen.png');
        itm := lsTextures.Items.Add;
        bmp.Assign(img.Picture.Bitmap);
        imgTextures.AddMasked(bmp,clFuchsia);
        itm.Caption := 'New Image';
        itm.ImageIndex := imgTextures.Count-1;
     finally
            bmp.Free;
            lsTextures.EndUpdate;
     end;
end;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20091122/b893fcd4/attachment.html>

Reply by email

Marc Weustink
to Matt Shaffer
Matt Shaffer wrote 6 lines
Hello, the code below is how I load and convert PNG files into BMPs, add them to a TImageList, and then add them to a TListView. The problem I'm having is that I cannot get the little bugger to scale to 96x96; other than that the code works. I would imagine that setting the timage's stretch property to true ought to scale the image to 96x96, but that was not the case.

TImage does not modify the original image, it only renders itself at the given size. IIRC you can pass a drawing rectange when drawing a graphic on a canvas.

Marc

Reply by email

Matt Shaffer
to Marc Weustink

The only rectangle I found when drawing to a canvas was DrawFocusRect(Rect: TRect); Nothing to do with drawing images, I'm afraid.

Marc Weustink wrote 25 lines
Matt Shaffer wrote: > Hello, the code below is how I load and convert PNG files into BMPs, add > them to a TImageList, and then add them to a TListView. The problem I'm > having is that I cannot get the little bugger to scale to 96x96; other than > that the code works. I would imagine that setting the timage's stretch > property to true ought to scale the image to 96x96, but that was not the > case. > TImage does not modify the original image, it only renders itself at the given size. IIRC you can pass a drawing rectange when drawing a graphic on a canvas. Marc -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20091122/11c1e6d0/attachment.html>

Reply by email

waldo kitty
to Matt Shaffer: Hello, the code below is how I load and convert PNG files into BMPs, add them to a…
Matt Shaffer wrote
Hello, the code below is how I load and convert PNG files into BMPs, add them to a TImageList, and then add them to a TListView.

as a "relative newbie" here (but not to coding in PASCAL), why do you have to convert to BMP? does the existing library (ie: LCL and FPC) code not accept PNG, GIF and similar for these graphic purposes?

Show quoted text 5 lines
The problem I'm having is that I cannot get the little bugger to scale to 96x96; other than that the code works. I would imagine that setting the timage's stretch property to true ought to scale the image to 96x96, but that was not the case.

sounds like it looks at the image properties for smaller scale with which to increase via the "stretch" routine... unlike other "stretch" routines which also reduce in size to the chosen params...

Show quoted text 38 lines
lsTextures: TListView; imgTextures: TImageList; procedure TForm1.MenuItem15Click(Sender: TObject); var bmp: TBitmap; img: TImage; itm: TListItem; begin bmp := TBitmap.Create; img := TImage.Create(nil); try lsTextures.BeginUpdate; img.Stretch := true; img.Width := 96; img.Height := 96; bmp.Width := 96; bmp.Height := 96; img.Picture.LoadFromFile('screen.png'); itm := lsTextures.Items.Add; bmp.Assign(img.Picture.Bitmap); imgTextures.AddMasked(bmp,clFuchsia); itm.Caption := 'New Image'; itm.ImageIndex := imgTextures.Count-1; finally bmp.Free; lsTextures.EndUpdate; end; end; ------------------------------------------------------------------------ -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Matt Shaffer
to waldo kitty
Show quoted text 7 lines
as a "relative newbie" here (but not to coding in PASCAL), why do you have to convert to BMP? does the existing library (ie: LCL and FPC) code not accept PNG, GIF and similar for these graphic purposes? I could not find a way programatically to load an image into a TImageList

from a file.

The only function I found was: TImageList.AddMasked(TBitmap,TColor); so I had to convert it to a tbitmap first.

Show quoted text 11 lines
The problem I'm having is that I cannot get the little bugger to scale to > 96x96; other than that the code works. I would imagine that setting the > timage's stretch property to true ought to scale the image to 96x96, but > that was not the case. > sounds like it looks at the image properties for smaller scale with which to increase via the "stretch" routine... unlike other "stretch" routines which also reduce in size to the chosen params...

I'm not sure. All I know is it didn't function as I would have expected. -------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20091122/af088bdb/attachment.html>

Reply by email