Solved

convert Jpeg to Bmp

Posted on 1999-01-07
10
469 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this Micro Tutorial viewers will learn how to remove an unwanted object using Photoshop’s feature known as content-aware fill.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

770 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