I am using Delphi7 with the KOL Components and JPegObj.
How can I transfer a PBitmap to PJpeg?
var
MyBitmap : PBitMap;
MyJpeg : PJpeg;
begin
MyBitMap := ....;
MyJPeg.Bitmap.Assign (MyBitMap); // ===> Wrong?
MyJPeg.SaveToFile ('C:\test.jpg');
end;
Thanks for your help.
EDIT: Picture here:

EDIT: My Code:
program Project2;
{$APPTYPE CONSOLE}
uses
Kol,
JpegObj;
var
Jpeg: PJpeg;
Bitmap: PBitmap;
begin
Bitmap := NewBitmap(50, 50);
try
Bitmap.Canvas.Brush.Color := $0000FF80;
Bitmap.Canvas.Ellipse(0, 0, 50, 50);
Jpeg := NewJpeg;
try
Jpeg.Bitmap := Bitmap;
Jpeg.SaveToFile('test.jpg');
finally
Jpeg.Free;
end;
finally
Bitmap.Free;
end;
Runtime Error 216 at 0041128E
EDIT:
I uncommented the line in JpegObj:
{$DEFINE VER62} // if you plan to use .obj-files from Delphi7 distributive only!
Now the program is just frozen.
EDIT: The program freezes here in JpegObj
function __ftol: Integer;
var
f: double;
begin
asm
lea eax, f // BC++ passes floats on the FPU stack
fstp qword ptr [eax] // Delphi passes floats on the CPU stack
end;
Result := Integer(Trunc(f));
end;
Disclaimer: The following has been tested on Delphi 2009!
You cannot use
PJpeg.Bitmap.Assignon yourPJpeginstance because thePJpeg.Bitmapis nil at the time you are accessing it since it’s not instantiated inPJpegconstructor nor later while you were working with that instance. So the attempt to work with thePJpeg.Bitmapleads to an access violation.Try to assign the bitmap this way (it’s based on the example from the
JpegObjextension):Here is a VCL minimalistic demo:
And the amazing result 🙂
Here is another, console minimalistic demo:
And the exciting result 🙂