Solved

Convert Png / Gif to Icon,  Bmp or thumbnail...

Posted on 2002-04-14
9
719 Views
Last Modified: 2013-11-19
Hi !
Archiving favourite websites as small pictures - perhaps as thumbnails - i'm looking for routines to convert png- and gif-pictures to bmp ( to icon or thumbnail is the best but this i can do with bmp by myself ;-)
If there's someone out knowing a bit please give me some hints or perhaps a source ? ...Or a link to a component ?
Thanks a lot,
Ingo
 
0
Comment
Question by:Ogni
  • 2
  • 2
  • 2
  • +2
9 Comments
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6941238
http://www.lischke-online.de/Graphics.html

This will add more file formats to TPicture.

Image1.Picture.LoadFromFile()
Image1.Picture.Bitmap.SaveToFile()

0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6941254
yeo, robert is right, the same i would have self suggested,
if not already done

meikl ;-)
0
 
LVL 1

Expert Comment

by:TAZI
ID: 6941316
Hi ...

I can help you with converting BMP to Icon. Herewith, Please find code

Hope this helps

Regards
TAZI

procedure bmp2ico(Image: TImage; FileName: TFilename);
var
  Bmp: TBitmap;
  Icon: TIcon;
  ImageList: TImageList;
begin
  Bmp  := TBitmap.Create;
  Icon := TIcon.Create;
  try
    Bmp.Assign(Image.Picture);
    ImageList := TImageList.CreateSize(Bmp.Width, Bmp.Height);
    try
      ImageList.AddMasked(Bmp, Bmp.TransparentColor);
      ImageList.GetIcon(0, Icon);
      // Save it to a file
      Icon.SaveToFile(FileName);
    finally
      ImageList.Free;
    end;
  finally
    Bmp.Free;
    Icon.Free;
  end;
end;  
 

procedure TForm1.Button1Click(Sender: TObject);
begin
  bmp2ico(Image1, 'c:\test.ico');
end;
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Ogni
ID: 6941415
Hi Robert,

it's not so easy... mmmh ?
I've done this and it don't work:

Image1.Picture.LoadFromFile(OpenDialog1.FileName);
Image1.Picture.RegisterFileFormat('png','Bitmap file',TBitmap);
Image1.Picture.Bitmap.SaveToFile('test.bmp');

Always errors like "...don't know fileformat..."

I think i need a special dcu (perhaps for monay ;-)

Any ideas?
Thanks a lot,
Ingo
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6941435
you must do an assignment to a tbitmap
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6941570
Do not call RegisterFileFormat.
As kretzschmar said Image1.Picture.Bitmap has to be assigned (from Image.Picture).
0
 
LVL 34

Expert Comment

by:Slick812
ID: 6943859
hello Ogni, Efg's is a web site I have found very helpful for Delphi graphics info and tips, this is the web page for file formats

http://www.efg2.com/Lab/Library/Delphi/Graphics/FileFormatsAndConversion.htm#Formats
0
 
LVL 34

Accepted Solution

by:
Slick812 earned 200 total points
ID: 6943887
Oh for thumbnails I have used this

var
Dimention: Cardinal;

Dimention := 90


procedure TfrmAlbum.ThumbNail(Pic1: TPicture; var ThumBmp: TBitmap);
var
Bmp1: TBitmap;
begin
ThumBmp.PixelFormat := pf24Bit;
if (Pic1.Width < Dimention) and (Pic1.Height < Dimention) then
    begin // 1
    ThumBmp.Height := Pic1.Height;
    ThumBmp.Width := Pic1.Width;
    end // 1
  else
  if Pic1.Width < Pic1.Height then
    begin // 2
    ThumBmp.Height := Dimention;
    ThumBmp.Width := Trunc(Dimention / (Pic1.Height / Pic1.Width))+2;
    end else // 2
  if Pic1.Width > Pic1.Height then
    begin // 3
    ThumBmp.Width := Dimention;
    ThumBmp.Height := Trunc(Dimention / (Pic1.Width / Pic1.Height))+2;
    end  else // 3
    begin // 4
    ThumBmp.Width := Dimention;
    ThumBmp.Height := Dimention;
    end; // 4
  if Pic1.Graphic.ClassType = TGIFImage then
    begin
    Bmp1 := TBitmap.Create;
    Bmp1.Width := Pic1.Width;
    Bmp1.Height := Pic1.Height;
    Bmp1.Assign(Pic1.Graphic);
    ThumBmp.Canvas.StretchDraw(Rect(0,0,ThumBmp.Width,ThumBmp.Height), Bmp1);
    FreeAndNil(Bmp1);
    end else
    ThumBmp.Canvas.StretchDraw(Rect(0,0,ThumBmp.Width,ThumBmp.Height), Pic1.Graphic);
end;


GotImage := True;
LoadPic := TPicture.Create;
try
LoadPic.LoadFromFile(ImagePath);
except
    on E: Exception do
    begin
    GotImage := False;
    end;
  end;
if GotImage then
begin // GotImage

  PicT := TBitmap.Create;
  ThumbNail(LoadPic,PicT);

Canvas.Draw(10,10,PicT);
FreeAndNil(PicT);
end;
FreeAndNil(LoadPic);
0
 

Author Comment

by:Ogni
ID: 6943992
Hi Slick812 !
Please give a few points to the other ones ;-)
Thanks a lot!
Ingo
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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 create interesting presentations by including videos to keep your audience engaged using Prezi. Select "Insert" from the top menu in your Prezi editor: Select "YouTube Video": Paste the video URL into the prompt: "Select "Insert":…

821 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