Board index » delphi » Bitmap to JPEG

Bitmap to JPEG


2006-10-09 06:56:32 AM
delphi259
How to load or assign a bitmap to jpg in Delphi 2006?
What is wrong in this? (Access violation)
ScanFotoImage.Picture.SaveToFile(ApuDir+'\Scan02.bmp');
jpg := TJPEGImage.Create;
jpg.DIBNeeded;
jpg.LoadFromFile(ApuDir+'\Scan02.bmp');
// jpg.Assign(ScanFotoImage.Picture.Graphic);
--
Asko Korpela
www.askokorpela.fi/
+358(0)50 529 9539
 
 

Re:Bitmap to JPEG

Asko Korpela writes:
Quote
How to load or assign a bitmap to jpg in Delphi 2006?
Just Google it! This is asked /all the time/.
www.google.com/search
I seem to remember that setting 'graphic' will free the old graphic for
you. In that case, you can use something like:
var jpg:TJpegImage;
jpg:=TJpegImage.create;
jpg.assign(ScanFotoImage.picture.graphic);
ScanFotoImage.picture:=jpg;
Quote
What is wrong in this? (Access violation)

jpg.LoadFromFile(ApuDir+'\Scan02.bmp');
A jpeg is not a bitmap, it understands nothing about loading bitmaps.
Cheers,
Nicholas Sherlock
--
www.sherlocksoftware.org
 

Re:Bitmap to JPEG

Nicholas Sherlock <XXXX@XXXXX.COM>writes:
Quote

[...] you can use something like:

var jpg:TJpegImage;

jpg:=TJpegImage.create;
jpg.assign(ScanFotoImage.picture.graphic);
ScanFotoImage.picture:=jpg;
That's close but not quite.
jpg := TJpegImage.create;
jpg.assign( the name of the TBitmap );
~ JD
 

Re:Bitmap to JPEG

Thank you. Did I understand correct
jpg := TJPEGImage.Create;
jpg.Assign(ApuDir+'\Scan01.bmp');
This follows:
[Pascal Error] Unit1.pas(122): E2010 Incompatible types: 'TPersistent' and
'string'
--
Asko Korpela
www.askokorpela.fi/
+358(0)50 529 9539
"JD" <XXXX@XXXXX.COM>kirjoitti
viestiss?4529b2c2$XXXX@XXXXX.COM...
Quote

Nicholas Sherlock <XXXX@XXXXX.COM>writes:
>
>[...] you can use something like:
>
>var jpg:TJpegImage;
>
>jpg:=TJpegImage.create;
>jpg.assign(ScanFotoImage.picture.graphic);
>ScanFotoImage.picture:=jpg;

That's close but not quite.

jpg := TJpegImage.create;
jpg.assign( the name of the TBitmap );

~ JD

 

Re:Bitmap to JPEG

See
www.scalabium.com/faq/dct0042.htm
for an example
For more examples:
google on 'Delphi bitmap jpeg'
Willem
Asko Korpela writes:
Quote
Thank you. Did I understand correct

jpg := TJPEGImage.Create;
jpg.Assign(ApuDir+'\Scan01.bmp');

This follows:
[Pascal Error] Unit1.pas(122): E2010 Incompatible types: 'TPersistent' and
'string'

--
Willem van Deursen, The Netherlands
XXXX@XXXXX.COM
replace _nospam@nospam_ for @ to get a valid email address
www.carthago.nl
 

Re:Bitmap to JPEG

Thank you very much.
The following really seems to work:
ApuBitmap.SaveToFile(ApuDir+'\Scan01.bmp');
ApuBitmap.Free;
ScanFotoImage.Picture.LoadFromFile(ApuDir+'\Scan01.bmp');
jpg := TJPEGImage.Create;
jpg.assign(ScanFotoImage.picture.graphic);
jpg.SaveToFile(ApuDir+'\Scan01.jpg');
ScanFotoImage.Picture.LoadFromFile(ApuDir+'\Scan01.jpg');
--
Asko Korpela
www.askokorpela.fi/
+358(0)50 529 9539
"Nicholas Sherlock" <XXXX@XXXXX.COM>kirjoitti
viestiss?XXXX@XXXXX.COM...
Quote
Asko Korpela writes:
>How to load or assign a bitmap to jpg in Delphi 2006?

Just Google it! This is asked /all the time/.

www.google.com/search

I seem to remember that setting 'graphic' will free the old graphic for
you. In that case, you can use something like:

var jpg:TJpegImage;

jpg:=TJpegImage.create;
jpg.assign(ScanFotoImage.picture.graphic);
ScanFotoImage.picture:=jpg;

>What is wrong in this? (Access violation)
>
>jpg.LoadFromFile(ApuDir+'\Scan02.bmp');

A jpeg is not a bitmap, it understands nothing about loading bitmaps.

Cheers,
Nicholas Sherlock

--
www.sherlocksoftware.org
 

Re:Bitmap to JPEG

This will get you just what you are looking for:
www.daniweb.com/code/snippet177.html
 

Re:Bitmap to JPEG

Make sure to free your jpg afterwards, (and add a try..finally block) to
avoid memory leaks.
...
ScanFotoImage.Picture.LoadFromFile(ApuDir+'\Scan01.bmp');
jpg := TJPEGImage.Create;
try
jpg.assign(ScanFotoImage.picture.graphic);
jpg.SaveToFile(ApuDir+'\Scan01.jpg');
finally
jpg.Free;
end;
ScanFotoImage.Picture.LoadFromFile(ApuDir+'\Scan01.jpg');
...
Willem
Asko Korpela writes:
Quote
Thank you very much.
The following really seems to work:

ApuBitmap.SaveToFile(ApuDir+'\Scan01.bmp');
ApuBitmap.Free;
ScanFotoImage.Picture.LoadFromFile(ApuDir+'\Scan01.bmp');
jpg := TJPEGImage.Create;
jpg.assign(ScanFotoImage.picture.graphic);
jpg.SaveToFile(ApuDir+'\Scan01.jpg');
ScanFotoImage.Picture.LoadFromFile(ApuDir+'\Scan01.jpg');

--
Willem van Deursen, The Netherlands
XXXX@XXXXX.COM
replace _nospam@nospam_ for @ to get a valid email address
www.carthago.nl
 

Re:Bitmap to JPEG

Asko Korpela writes:
Quote
Thank you very much.
The following really seems to work:

ApuBitmap.SaveToFile(ApuDir+'\Scan01.bmp');
ApuBitmap.Free;
ScanFotoImage.Picture.LoadFromFile(ApuDir+'\Scan01.bmp');
jpg := TJPEGImage.Create;
jpg.assign(ScanFotoImage.picture.graphic);
jpg.SaveToFile(ApuDir+'\Scan01.jpg');
ScanFotoImage.Picture.LoadFromFile(ApuDir+'\Scan01.jpg');
Why are you saving the bitmap to disk? Do you want a bitmap saved to
disk? Do you want a jpeg saved to disk? If you really need the bitmap on
disk, and want to show the jpeg in your picture afterwards, use:
ApuBitmap.SaveToFile(ApuDir+'\Scan01.bmp');
jpg := TJPEGImage.Create;
jpg.assign(ApuBitmap);
ApuBitmap.Free;
jpg.SaveToFile(ApuDir+'\Scan01.jpg');
ScanFotoImage.Picture.Graphic:=jpg;
If you don't really need the bitmap, you can use:
jpg := TJPEGImage.Create;
jpg.assign(ApuBitmap);
ApuBitmap.Free;
jpg.SaveToFile(ApuDir+'\Scan01.jpg');
ScanFotoImage.Picture.Graphic:=jpg;
Cheers,
Nicholas Sherlock
--
www.sherlocksoftware.org