Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

convert Jpeg to Bmp

Posted on 1999-01-07
10
Medium Priority
?
476 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

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…
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…
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…
It’s easy to embed any of your public Prezi presentations on your website or social network to share with others. Learn how simple it is in this tutorial.
Suggested Courses

670 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