Solved

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

Posted on 2002-04-14
9
716 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 33

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 33

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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":…

920 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

13 Experts available now in Live!

Get 1:1 Help Now