别人写的一个控件的源码,希望对你有帮助!
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.