Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

convert Jpeg to Bmp

Posted on 1999-01-07
10
Medium Priority
?
477 Views
Last Modified: 2013-11-19
I need to save jpeg files into bmp and vice versa.
I need this converstion to save jpeg images into database as a Blob.

please help
Motaz
0
Comment
Question by:Motaz
10 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1355119
Use a TImage component with the JPEG source that comes with Delphi (ie: add the jpeg unit to your main uses clause and your done).

Then just read the jpeg in like this:

image1.picture.loadfromfile('pic.jpg');

then the bitmap version of it is available as (say you save it to a file...or whatever ):

image1.picture.bitmap.savetofile('pic.bmp');

Cheers,

Raymond.

0
 
LVL 7

Author Comment

by:Motaz
ID: 1355120
Thanks, but how can I save jpeg into BLOB field ?
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1355121
Use the LoadFromFile or LoadFromStream methods of the TBlobField class.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Author Comment

by:Motaz
ID: 1355122
Hello there. it didn't work, the BitMap in the picture properity contain nil, because the picutre is not bitmap it is Jpeg.

Motaz
0
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 100 total points
ID: 1355123
OK, create another TImage and do this (you will need to make its size the same as the JPEG etc:

      image1.picture.bitmap.assign(LicenseeImage.picture.graphic);

Then the image1.picture.bitmap has a BMP in it - save this to your BMP file...

Cheers,

Raymond.

0
 

Expert Comment

by:joanita
ID: 1355124
Keep in mind that there can be no transparency in a bmp image
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1355125
joanita: What does transparency have to do with converting a JPEG to BMP?

Raymond.
0
 
LVL 7

Author Comment

by:Motaz
ID: 1355126
Okay Raymond. How can I convert Bmp to Jpeg ?
Motaz
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1355127
This is probably a little trickier when using a TImage directly. You could probably use a TJPEGImage, or bmptojpg.zip on DSP (http:/sunsite.icm.edu.pl/delphi)

Cheers,

Raymond.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1355128
hi motaz,

i must append something in this last standing answered q

here is a little unit,
which converts as you want

     unit jpbmp_u;

     interface

     uses
       Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
       StdCtrls, ExtDlgs, ExtCtrls ,JPeg;  // JPeg is used

     type
       TForm1 = class(TForm)
         Image1: TImage;
         SavePictureDialog1: TSavePictureDialog;
         OpenPictureDialog1: TOpenPictureDialog;
         Bt_Load: TButton;
         Bt_Save_JPG: TButton;
         BT_Save_BMP: TButton;
         procedure Bt_LoadClick(Sender: TObject);
         procedure Bt_Save_JPGClick(Sender: TObject);
         procedure BT_Save_BMPClick(Sender: TObject);
       private
         { Private-Deklarationen }
       public
         { Public-Deklarationen }
       end;

     var
       Form1: TForm1;

     implementation

     {$R *.DFM}

     procedure TForm1.Bt_LoadClick(Sender: TObject);  Load BMP or JPG
     begin
       if openpictureDialog1.Execute then
         image1.Picture.LoadFromFile(openpictureDialog1.FileName);

     end;

     procedure TForm1.Bt_Save_JPGClick(Sender: TObject);
     var
       JPGImage : TJPegImage;
     begin
       If (image1.Picture.Graphic is TBitmap) then  //Bitmap available
         if SavepictureDialog1.Execute then
         begin
           JPGImage := TJPEGImage.Create;
           JPGImage.Assign(TBitmap(image1.Picture.Graphic));
           JPGImage.SaveToFile(SavepictureDialog1.FileName);
           JPGImage.Free;
         end;
     end;

     procedure TForm1.BT_Save_BMPClick(Sender: TObject);
     var
       BMPImage : TBitMap;
     begin
       If (image1.Picture.Graphic is TJpegImage) then  //JPeg Available
         if SavepictureDialog1.Execute then
         begin
           BMPImage := TBitMap.Create;
           BMPImage.Assign(TJpegImage(image1.Picture.Graphic));
           BMPImage.SaveToFile(SavepictureDialog1.FileName);
           BMPImage.Free;
         end;
     end;

     end.

meikl
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Learn the basics of inputting and editing your text components in Prezi. We will cover how to set styles, position, and group your text components. In your Prezi editor, click anywhere on the canvas to add text: A flashing cursor informs you that yo…
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question