寻找把bmp转jpg的控件最好附源码.(50分)

  • 主题发起人 主题发起人 铃铛
  • 开始时间 开始时间

铃铛

Unregistered / Unconfirmed
GUEST, unregistred user!
寻找把bmp的文件转为jpg格式文件的控件.只要把个是转换一下即可.
最好附源码.
 
刚才我试着做了一个,没什么问题。

function BmpToJpeg(SourceBMP:TBitMap;CompressQ:Integer):TJPEGImage ;
var R:TJPEGImage;
begin
R:=TJPEGImage.Create;
R.Assign(SourceBMP);
R.JPEGNeeded;
R.CompressionQuality:=CompressQ;
R.Compress;
R.SaveToFile('C:/A.JPG');
Result:=R;
R.free;
end;

别忘记给分啊。
 
我给你个控件.
 
下面的代码来自uddf,其实质同menxin的一样:
var
MyJpeg: TJpegImage;
Image1: TImage;
begin
Image1:= TImage.Create;
MyJpeg:= TJpegImage.Create;
Image1.LoadFromFile('TestImage.BMP'); // Load the Bitmap from a file
MyJpeg.Assign(Image1.Picture.Bitmap); // Assign the BitMap to MyJpeg
object
MyJpeg.SaveToFile('MyJPEGImage.JPG'); // Save the JPEG to Disk
end;
 
别人写的一个控件的源码,希望对你有帮助!:)


unit BmpToJpg;
{-----------------------------------------------------------------------------}
{ TBmpToJpeg v 1.0 }
{ Copyright 1998, Eric Pedrazzi. All Rights Reserved. }
{-----------------------------------------------------------------------------}
{ A component to translate a bitmap file into a jpeg one }
{ }
{ This component can be freely used and distributed in commercial and private }
{ environments, provied this notice is not modified in any way and there is }
{ no charge for it other than nomial handling fees. Contact me directly for }
{ modifications to this agreement. }
{ }
{-----------------------------------------------------------------------------}
{ Feel free to contact me if you have any questions, comments or suggestions }
{ at epedrazzi@chez.com }
{ The latest version will always be available on the web at: }
{ http://www.chez.com/epedrazzi/epdelphuk or }
{ http://www.chez.com/epedrazzi/epdelphfr }
{ See BmpToJpg.txt for notes, known issues, and revision history. }
{-----------------------------------------------------------------------------}
{ Date last modified: November 1998 }
{-----------------------------------------------------------------------------}
{ v1.0 : Initial release }
{-----------------------------------------------------------------------------}

{ This unit provides an invisible component to perform a copy of a bitmap file
to a jpeg file.

Properties
----------
BmpFile : Source File in bitmap format
JpegFile : Destination file in Jpeg format

Methods
-------
ExecCopyBmpToJpg : Start translation

}

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Jpeg;

type
TBmpToJpeg = class(TComponent)
private
{ D閏larations priv閑s }
FStream : TStream;
FJpeg : TJpegImage;
FBmp : TPicture;
FBmpFile : AnsiString;
FJpegFile: AnsiString;
protected
{ D閏larations prot間閑s }
procedure FCopyBmpToJpeg;
public
{ D閏larations publiques }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure ExecCopyBmpToJpeg;
published
{ D閏larations publi閑s }
property BmpFile : AnsiString read FBmpFile write FBmpFile;
property JpegFile: AnsiString read FJpegFile write FJpegFile;
end;

procedure Register;

implementation

procedure TBmpToJpeg.FCopyBmpToJpeg;
begin
if FileExists(FJpegFile) then DeleteFile(FJpegFile);
FStream := TFileStream.Create(FJpegFile,fmCreate);
try
FBmp.LoadFromFile(FBmpFile);
FJpeg.Assign(FBmp.Bitmap);
FJpeg.SaveToStream(FStream);
finally
FStream.Free;
end;
end;

constructor TBmpToJpeg.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FJpeg := TJpegImage.Create;
FBmp := TPicture.Create;
end;

destructor TBmpToJpeg.Destroy;
begin
FJpeg.Free;
FBmp.Free;
inherited Destroy;
end;

procedure TBmpToJpeg.ExecCopyBmpToJpeg;
begin
FCopyBmpToJpeg;
end;

procedure Register;
begin
RegisterComponents('VCL', [TBmpToJpeg]);
end;

end.

 
这么多人写了,我就不多说了,
解释几句:
1、TJpegImage是Delphi自己带的对象,继承自TGrapihc,和TBitmap同级。
2、Assign方法定义在TPersistent中,目的是实现永久类的数据保存,一般
凡是相容的类,都可以用Assign方法拷贝数据。
 
铃铛:

这个问题已经很长时间没有人参加讨论,为保持版面
整洁,节约网友时间,请提问者采取必要处理措施。
关于图形图象版管理细则,请参见<a href="http://www.gislab.ecnu.edu.cn/delphibbs/DispQ.asp?LID=111927">这个</a>问题。如两天
内提问者没有响应,我将采取强制措施。

如有管理建议,请到<a href="http://www.gislab.ecnu.edu.cn/delphibbs/DispQ.asp?LID=111927">这里</a>提出。谢谢!
 
不用怀疑,menxin的做法是绝对没错的!
李颖同志的说法也无问题。
JJLEI同志的程序中TImage在Create时要带上一些东东!
 
delphi 3 client/server的光碟上有!
另外还有一些好东西,如DEMOSHIELD 4 等。
如有人要DEMOSHIELD5
请到 ftp://tracy.bupt.edu.cn/ComeInHere/
DeveloperTools/InstallTools/DemoShield/
 
多人接受答案了。
 
后退
顶部