Solved

convert Jpeg to Bmp

Posted on 1999-01-07
10
467 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
 
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 50 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial viewers will learn how to create blended and gradiated shapes in Illustrator using the blend tool Draw two shapes, one of them in a different color: Select both and create a blend by going to Object > Blend > Make: Blends can also b…
Learn how to set up basic frames and paths in Prezi and understand the open space that Prezi allows you to create presentations in.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now