Re:Drawing over a JPEG image
Aldo,
The trick is to convert the jpeg to a bitmap, do any drawing on the
bitmap and then convert back to a jpeg. Below is something I put
together when I was working through these things.
Bob
----
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
Jpeg, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
JPEG: TJPEGImage;
BMP : TBitmap;
begin
JPEG := TJPEGImage.create;
BMP := TBitmap.create;
JPEG.LoadFromFile( 'factory.jpg' );
{If you need to draw on a jpeg, convert to bmp and draw on the bitmap
canvas
BMP.Height := JPEG.Height;
BMP.Width := JPEG.Width;
BMP.Canvas.Draw(10,10, JPEG); }
BMP.Assign(JPEG);
Image1.Picture.Graphic:= BMP;
JPEG.free;
Bmp.free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
jp: TJpegImage;
bmp: TBitmap;
const filename = 'factory.bmp';
begin
bmp:= Tbitmap.Create;
try
bmp.Loadfromfile(filename);
jp:= TJpegImage.Create;
try
jp.Assign( bmp );
jp.SaveToFile( ChangeFileExt( filename, '.JPG' ));
ShowMessage('Bitmap converted to JPeg');
finally
jp.free
end;
finally
bmp.free
end;
end;
end.