HelpMEDude
Programmer
Hello, once again, for those who remember me ^^!
I've tried to make a procedure that simply loads any frequently used image type (jpg, gif etc.) and then converts it to a 24 or 8-bit bmp-file.
I decided that OLE was a good solution for this, since it's built-in in Delphi and all...
I'd wrote this code, inspired from the delphitricks website:
I saw somehow the output image was in wrong size, and when I debugged, I put a breakpoint at line bm.width:=etc. .I found out that the width and height are about 10 percent lower than the real dimensions of the image. It applies to both gif and bmp files I load (I have not tested other).
So reading images with TOleGraphic fails, if you guys know what the solution to this is, or other way to convert images to bmp 24 and 8-bit. Please help me.
I use Delphi 2005, in case of that will matter.
Thanks in advice
I've tried to make a procedure that simply loads any frequently used image type (jpg, gif etc.) and then converts it to a 24 or 8-bit bmp-file.
I decided that OLE was a good solution for this, since it's built-in in Delphi and all...
I'd wrote this code, inspired from the delphitricks website:
Code:
procedure ImageToBmp(Source :Tfilename; Destination :Tfilename; format :TPixelformat ;Forcewidth:integer; ForceHeight:integer);
var
OleGraphic: TOleGraphic;
fs: TFileStream;
BM : Tbitmap;
begin
try
OleGraphic := TOleGraphic.Create;
fs := TFileStream.Create(Source, fmOpenRead or fmSharedenyNone);
OleGraphic.LoadFromStream(fs);
bm:=Tbitmap.Create;
Bm.PixelFormat := format;
if (Forcewidth=0) and (ForceHeight=0) then begin
bm.Height:= OleGraphic.Height;
bm.Width:= OleGraphic.Width;
bm.Canvas.Draw(0,0,OleGraphic);
end else begin
Bm.Height := ForceHeight;
Bm.Width := Forcewidth;
bm.Canvas.StretchDraw(rect(point(0,0),point(Forcewidth,ForceHeight)),OleGraphic);
end;
bm.SaveToFile(Destination);
finally
bm.Free;
fs.Free;
OleGraphic.Free
end;
end;
I saw somehow the output image was in wrong size, and when I debugged, I put a breakpoint at line bm.width:=etc. .I found out that the width and height are about 10 percent lower than the real dimensions of the image. It applies to both gif and bmp files I load (I have not tested other).
So reading images with TOleGraphic fails, if you guys know what the solution to this is, or other way to convert images to bmp 24 and 8-bit. Please help me.
I use Delphi 2005, in case of that will matter.
Thanks in advice