Solved

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

Posted on 2002-04-14
9
723 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
[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
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Keep your audience engaged and get the most out of your next presentation with these quick Prezi tips.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Learn how to set up basic frames and paths in Prezi and understand the open space that Prezi allows you to create presentations in.
Suggested Courses

617 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