Forum > Graphics

Confusion with image formats

(1/3) > >>

Tomi:
Hello!

I use a TOpenPictureDialog in my program to open different images. With this dialog box possible to open different image formats, e.g. .BMP, .JPG, .GIF, etc.
But what if I want use these image formats in my program, not only the .BMPs? So, I would like open it and then perform various actions on it, e.g. draw on a certain coordinate or copy a part of it onto another image.
Now, all of my images are TBitmap in my program, therefore when I try to open a different format (.JPG, .GIF, etc.) with TOpenPictureDialog, I get an error message about wrong image format.
This solution is good:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if fileOpener.Execute then   begin     sourceimage:=TBitmap.Create;     sourceimage.LoadFromFile(fileOpener.FileName);and later I can use this sourceimage with drawing and with copyrect() function, for example.
But which type do I need to use other image formats? TImage? TGraphic? TPicture? I tried these, but the result is the total confusion in my program, e.g. because I just could draw only TBitmaps with Form1.canvas.draw().
So, can only .BMPs be used or is there a solution to use all supported image formats? For example, transform the opened file type to .BMP within the program? Or can I solely use TBitmap and BMPs?

lainz:
Use BGRABitmap, you can use more than BMP with that...


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---bgra := TBGRABitmap.Create('file.jpg')

wp:
When you create an image as TBitmap - yes, you can only load bmp files into it. But the LCL has a multi-format class, named TPicture. You can load any format and access the data as its Graphic property:

Untested:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var  pic: TPicture;...  if FileOpener.Execute then  begin    pic := TPicture.Create;    pic.LoadFromFile(fileOpener.FileName);    // Example: crop the center 100x100 pixels into a bitmap    bmp := TBitmap.Create;    bmp.SetSize(100, 100);    bmp.Canvas.Draw((pic.Width - bmp.Width) div 2, pic.Height - bmp.Height) div 2, pic.Graphic);    bmp.SaveToFile('cropped.bmp');    bmp.Free;

circular:
Indeed, TPicture handles multiple formats. You may need to add FPRead*/FPWrite* to the uses clause.

cdbc:
Hi
Have you tried:
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if fileOpener.Execute then  Image1.Picture.LoadFromFile(fileOpener.FileName); The 3 answers above are better, but I think this should work too...
Regards Benny

Navigation

[0] Message Index

[#] Next page

Go to full version