Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
500 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (0)


Convert BMP to *Any Format* (.NET)Format this article printer-friendly!Bookmark function is only available for registered users!
Product:
Delphi 8 for .NET
Category:
Graphic
Skill Level:
Scoring:
Last Update:
01/12/2005
Search Keys:
delphi delphi3000 article borland vcl code-snippet convert image bitmap bmp jpg jpeg GIF PNG .NET Delphi-8 Delphi-2005 Diamondback FileStream Drawing Imaging IO
Times Scored:
3
Visits:
3667
Uploader: Eber Irigoyen
Company: BTXSys
Reference: N/A
 
Question/Problem/Abstract:
When working in .NET you pretty much have to re-learn the VCL, (FCL) to accomplish every single task

there's tons of code for Win32 to convert images to/from formats, here I show  you how to convert an Image from BMP to any format (JPG, PNG, GIF, etc) in .NET
Answer:



the FCL provides methods to do many image manipulation tricks, you just have to know where to find them

this function will do the job for you

procedure TWinForm3.Bmp2AnyFormat(theBmp:Bitmap; const FileName:string; const ImgFormat:ImageFormat);
var
  fs:FileStream;
begin
  fs:=FileStream.Create(FileName, FileMode.CreateNew);
  try try
    theBmp.Save(fs, ImgFormat);
  except
    on E:Exception do
      raise Exception.Create('Error converting image: '+E.Message);
  end finally
    fs.Close
  end
end;

the Bitmap class comes from
System.Drawing.Imaging

the FileStream comes from:
System.IO

so you'll need those in your uses clause

now, an example of use:
say you have a PictureBox with a .BMP on it in your form, and you wanted to save that as a jpeg

I put some code to load a bmp at runtime:
procedure TWinForm3.TWinForm3_Load(sender: System.Object; e: System.EventArgs);
begin
  PictureBox1.Image:=Image.FromFile('c:\SomeFile.bmp');
end;

then a button to convert the image (to JPEG) using the function:
procedure TWinForm3.Button1_Click(sender: System.Object; e: System.EventArgs);
begin
  Bmp2AnyFormat(Bitmap(PictureBox1.Image), 'f:\new.jpg', ImageFormat.Jpeg)
end;

you can use
ImageFormat.Tiff,
ImageFormat.Gif,
ImageFormat.Png,
ImageFormat.Jpeg,
etc...

that's it, as you can see, is really easy... the hard part is to find which class does what

best regards





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment













 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
E. Irigoyen
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)