我找到了一种更简单的方法!它自动加载JPG / GIF / BMP等文件,而无需知道/检查文件格式,然后进行相应转换。它对我来说非常有效。
在这里分享:)
Uses
Classes, ExtCtrls, Graphics, axCtrls;
Procedure TForm1.Button1Click(Sender: TObject);
Var
OleGraphic : TOleGraphic;
fs : TFileStream;
Source : TImage;
BMP : TBitmap;
Begin
Try
OleGraphic := TOleGraphic.Create; {The magic class!}
fs := TFileStream.Create('c:\testjpg.dat', fmOpenRead Or fmSharedenyNone);
OleGraphic.LoadFromStream(fs);
Source := Timage.Create(Nil);
Source.Picture.Assign(OleGraphic);
BMP := TBitmap.Create; {Converting to Bitmap}
bmp.Width := Source.Picture.Width;
bmp.Height := source.Picture.Height;
bmp.Canvas.Draw(0, 0, source.Picture.Graphic);
image1.Picture.Bitmap := bmp; {Show the bitmap on form}
Finally
fs.Free;
OleGraphic.Free;
Source.Free;
bmp.Free;
End;
End;
0
我必须从XML文件加载图像。 XML文件中没有有关图像是否为JPG / GIF / BMP的信息。加载图像后,我需要将其转换为位图。
没有人知道如何将图像转换为位图的任何线索吗?我正在使用Delphi 2007/2009
谢谢。