Solved

convert Jpeg to Bmp

Posted on 1999-01-07
10
466 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
In this Micro Tutorial viewers will learn the basic shortcuts and functions of Illustrator. The viewer will learn about the paintbrush tool, anchor points, font sizing, and more.
Learn how to set up basic frames and paths in Prezi and understand the open space that Prezi allows you to create presentations in.

705 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

20 Experts available now in Live!

Get 1:1 Help Now