TBitmap问题,图象专家please come in

Michaelyfj 2000-07-17 06:37:00
各位高手:
如何把TBitmap的内容保存为.Jpg文件格式?(特急)
...全文
130 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
IAmKylix 2000-07-18
  • 打赏
  • 举报
回复
大家都说了,我来晚了。
halfdream 2000-07-17
  • 打赏
  • 举报
回复
唉。前两位朋友已经说得很完全,没有什么好补充的了。
TBitmap 和TJPEGImage 都继承自TGraphics,相互赋值都很方便。
aiirii 2000-07-17
  • 打赏
  • 举报
回复
uses Jpeg;

private
Jpg:TJpegImage;Bmp:Tbitmap;

procedure Tjpg_bmp.Button3Click(Sender: TObject);
begin
if bmp<>nil then bmp:=nil;
Opendialog1.Filter:='Bitmap(*.bmp)|*.bmp';
Opendialog1.DefaultExt:='*.Bmp';
Opendialog1.Filename:='';
opendialog1.Execute;
if Opendialog1.Filename<>'' then
begin
Bmp:=TBitmap.Create;
Bmp.LoadFromFile(Opendialog1.FileName);
Image1.Picture.LoadFromFile(Opendialog1.FileName);
end;
end;


procedure Tjpg_bmp.Button4Click(Sender: TObject);
begin
if jpg<>nil then jpg:=nil;
Savedialog1.filename:='';
Savedialog1.Filter:='Jpeg(*.jpg)|*.jpg';
Savedialog1.DefaultExt:='*.jpg';
SaveDialog1.Execute;
if Savedialog1.filename<>'' then
begin
Jpg:=TJpegImage.Create;
Jpg.Assign(Bmp);
Jpg.CompressionQuality:=StrToInt(Edit1.Text);
Jpg.Compress;
Jpg.SaveToFile(Savedialog1.FileName);
Jpg.Free;
end;
end;
Wingsun 2000-07-17
  • 打赏
  • 举报
回复
新生成一个TJPEGImage类的数据,然后如下:
TJPEGImage * pImage=new TJPEGImage();
pImage->Assign(pBitmap);
pImage->SaveToFile("D:\Temp.jpg");
delete pImage;
这是BCB的语法,将其该成Delphi的语法即可。
procedure BitmapFileToPNG(const Source, Dest: String); var Bitmap: TBitmap; PNG: TPNGObject; begin Bitmap := TBitmap.Create; PNG := TPNGObject.Create; {In case something goes wrong, free booth Bitmap and PNG} try Bitmap.LoadFromFile(Source); PNG.Assign(Bitmap); //Convert data into png PNG.SaveToFile(Dest); finally Bitmap.Free; PNG.Free; end end; Converting from PNG file to Windows bitmap file The above inverse. Loads a png and saves into a bitmap procedure PNGFileToBitmap(const Source, Dest: String); var Bitmap: TBitmap; PNG: TPNGObject; begin PNG := TPNGObject.Create; Bitmap := TBitmap.Create; {In case something goes wrong, free booth PNG and Bitmap} try PNG.LoadFromFile(Source); Bitmap.Assign(PNG); //Convert data into bitmap Bitmap.SaveToFile(Dest); finally PNG.Free; Bitmap.Free; end end; Converting from TImage to PNG file This method converts from TImage to PNG. It has full exception handling and allows converting from file formats other than TBitmap (since they allow assigning to a TBitmap) procedure TImageToPNG(Source: TImage; const Dest: String); var PNG: TPNGObject; BMP: TBitmap; begin PNG := TPNGObject.Create; {In case something goes wrong, free PNG} try //If the TImage contains a TBitmap, just assign from it if Source.Picture.Graphic is TBitmap then PNG.Assign(TBitmap(Source.Picture.Graphic)) //Convert bitmap data into png else begin //Otherwise try to assign first to a TBimap BMP := TBitmap.Create; try BMP.Assign(Source.Picture.Graphic); PNG.Assign(BMP); finally BMP.Free; end; end; //Save to PNG format PNG.SaveToFile(Dest); finally PNG.Free; end end;
Version 1.7 ----------- - ADD: Delphi/CBuilder 10.2 Tokyo now supported. - ADD: Delphi/CBuilder 10.1 Berlin now supported. - ADD: Delphi/CBuilder 10 Seattle now supported. - ADD: Delphi/CBuilder XE8 now supported. - ADD: Delphi/CBuilder XE7 now supported. - ADD: Delphi/CBuilder XE6 now supported. - ADD: Delphi/CBuilder XE5 now supported. - ADD: Delphi/CBuilder XE4 now supported. - ADD: Delphi/CBuilder XE3 now supported. - ADD: Delphi/CBuilder XE2 now supported. - ADD: Delphi/CBuilder XE now supported. - ADD: Delphi/CBuilder 2010 now supported. - ADD: Delphi/CBuilder 2009 now supported. - ADD: New demo project FlexCADImport. - FIX: The height of the TFlexRegularPolygon object incorrectly changes with its rotation. - FIX: Added division by zero protect in method TFlexControl.MovePathSegment. - FIX: The background beyond docuemnt wasn't filled when TFlexPanel.DocClipping=True. - FIX: In "Windows ClearType" font rendering mode (OS Windows mode) the "garbage" pixels can appear from the right and from the bottom sides of the painted rectangle of the TFlexText object. - FIX: The result rectangle incorrectly calculated in the TFlexText.GetRefreshRect method. - FIX: Added FPaintCache.rcPaint cleanup in the TFlexPanel.WMPaint method. Now it is possible to define is the drawing take place via WMPaint or via the PaintTo direct call (if rcPaint contain non-empty rectangle then WMPaint in progress). - FIX: The TFlexPanel.FPaintCache field moved in the protected class section. Added rcPaint field in FPaintCache that represents drawing rectangle. - ADD: In the text prcise mode (TFlexText.Precise=True) takes into account the rotation angle (TFlexText.Angle). - FIX: Removed FG_NEWTEXTROTATE directive (the TFlexText Precise mode should be used instead). - FIX: The TFlexRegularPolygon object clones incorrectly drawed in case when TFlexRegularPolygon have alternative brush (gradient, texture). - ADD: Add TFlexPanel.InvalidateControl virtual method which calls from TFle

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧