Solved

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

Posted on 2002-04-14
9
715 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
Comment Utility
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
Comment Utility
yeo, robert is right, the same i would have self suggested,
if not already done

meikl ;-)
0
 
LVL 1

Expert Comment

by:TAZI
Comment Utility
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
 

Author Comment

by:Ogni
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
you must do an assignment to a tbitmap
0
 
LVL 11

Expert Comment

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

Expert Comment

by:Slick812
Comment Utility
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 33

Accepted Solution

by:
Slick812 earned 200 total points
Comment Utility
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
Comment Utility
Hi Slick812 !
Please give a few points to the other ones ;-)
Thanks a lot!
Ingo
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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…
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now