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

x
?
Solved

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

Posted on 2002-04-14
9
Medium Priority
?
728 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 600 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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
In this Micro Tutorial viewers will learn how to remove an unwanted object using Photoshop’s feature known as content-aware fill.
Learn how to download your full Prezi presentation for offline presenting. Prezi doesn’t have to be viewed and shared in a web browser, even with a free account you can download your full presentation to share with others. Be sure to download any vi…
Suggested Courses

705 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