Getting image (bmp, png) size? lazarus / 13-General ---------------------------------------------------------------------- Anonymous · 2005-11-25 02:19 Hello, I'm having a hard time finding a way to get the image size (height and width) of an image that would be opened by an openpicturedialog.execute. The image loaded would be a bmp or a png depending on the situation. I want to be able to resize something an user would load in order to make it fit into a regular size (120*90 pixels in my case). How should I proceed (I'm a beginner)? I looked around on delphi websites and so far nothing seems to work...  :cry: Thanks for any help... ---------------------------------------------------------------------- Anonymous · 2005-11-25 09:57 What is exactly your problem? Maybe setting TImage.Stretch to True does the job? ---------------------------------------------------------------------- fab25 · 2005-11-25 14:17 Hi, Thanks a lot. I was trying to code eveything where a single set to true did all the job... Duh! Is there an easy way to export the picture loaded in the Timage as a png regardless of the format of the original? Thanks again ---------------------------------------------------------------------- rjmatm · 2005-12-02 04:45 Well, as far as converting your images to PNG no matter the original format I have a way.  It's might seem a little long but it works. Code: [Select]Uses .. LCLIntf, LCLType The below can be converted to its own procedure but for simplicity I just used a button click event. Image1 is an image component placed on the form. Maybe someone can help to show a better/quicker way, but this seems to work for me. Code: [Select]procedure TForm1.Button1Click(Sender: TObject); var png_img: TPortableNetworkGraphic; RGBValues: TRGBQUAD; j, k: Integer; begin   // Below the code reads the canvas so this is needed   // If the image shown on the form is the size and configured how you   // want it then comment out the next two lines so the size of the Image1   // is not changed.   Image1.AutoSize := True;   Image1.Refresh;   png_img := TPortableNetworkGraphic.Create;     // Set png_img width and height equal to the image's width and height   png_img.Width := Image1.Picture.Width;   png_img.Height := Image1.Picture.Height;     // Loop through the pixels   for j := 0 to Image1..PictureWidth - 1 do     begin         for k := 0 to Image1.Picture.Height - 1 do       begin               // Get the RGB values of each pixel         RGBValues.rgbRed   := Byte(Image1.Canvas.Pixels[j, k]);         RGBValues.rgbGreen := Byte(Image1.Canvas.Pixels[j, k] shr 8);         RGBValues.rgbBlue  := Byte(Image1.Canvas.Pixels[j, k] shr 16);                 // Set the pixel RGB values         // Basically copy the colors from the Image1 to the png_img variable         png_img.Canvas.Pixels[j, k] := RGB(RGBValues.rgbRed, RGBValues.rgbGreen, RGBValues.rgbBlue);       end;         end;       // Save the PNG to a file   png_img.SaveToFile('my_png.png');   end; I hope this helps.