📄 rm_e_jpeg.pas
字号:
unit RM_e_Jpeg;
interface
{$I RM.INC}
{$IFDEF JPEG}
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, RM_Class, RM_E_Graphic, JPEG, ComCtrls;
type
{ TRMJPEGExport }
TRMJPEGExport = class(TRMGraphicExport)
private
FGrayscale: Boolean;
FProgressiveEncoding: Boolean;
FQuality: TJPEGQualityRange;
FPixelFormat: TPixelFormat;
public
constructor Create(AOwner: TComponent); override;
function ShowModal: Word; override;
procedure OnEndPage; override;
published
property Grayscale: Boolean read FGrayscale write FGrayscale default False;
property ProgressiveEncoding: Boolean read FProgressiveEncoding write FProgressiveEncoding default True;
property Quality: TJPEGQualityRange read FQuality write FQuality default High(TJPEGQualityRange);
property PixelFormat: TPixelFormat read FPixelFormat write FPixelFormat default pf24bit;
end;
{ TRMJPEGExportForm }
TRMJPEGExportForm = class(TForm)
btnOK: TButton;
btnCancel: TButton;
gbJPEG: TGroupBox;
lblQuality: TLabel;
chkGrayscale: TCheckBox;
chkProgressiveEncoding: TCheckBox;
edQuality: TEdit;
Label1: TLabel;
Label2: TLabel;
edScaleX: TEdit;
Label3: TLabel;
edScaleY: TEdit;
UpDown1: TUpDown;
Label4: TLabel;
cmbPixelFormat: TComboBox;
procedure FormCreate(Sender: TObject);
procedure edQualityKeyPress(Sender: TObject; var Key: Char);
private
procedure Localize;
protected
public
end;
{$ENDIF}
implementation
{$IFDEF JPEG}
uses RM_CmpReg, RM_Const, RM_Utils;
{$R *.DFM}
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{TRMJPEGExport}
constructor TRMJPEGExport.Create(AOwner: TComponent);
begin
inherited;
FGrayscale := False;
FPixelFormat := pf24bit;
FProgressiveEncoding := True;
FQuality := High(TJPEGQualityRange);
FFileExtension := 'jpg';
RMRegisterExportFilter(Self, RMLoadStr(SJPEGFile), '*.jpg');
end;
function TRMJPEGExport.ShowModal: Word;
begin
if not ShowDialog then
Result := mrOk
else
begin
with TRMJPEGExportForm.Create(nil) do
begin
try
edScaleX.Text := FloatToStr(Self.ScaleX);
edScaleY.Text := FloatToStr(Self.ScaleY);
chkGrayscale.Checked := Self.Grayscale;
chkProgressiveEncoding.Checked := Self.ProgressiveEncoding;
UpDown1.Position := Self.Quality;
cmbPixelFormat.ItemIndex := Integer(Self.PixelFormat);
Result := ShowModal;
if Result = mrOK then
begin
Self.ScaleX := StrToFloat(edScaleX.Text);
Self.ScaleY := StrToFloat(edScaleY.Text);
Self.Grayscale := chkGrayscale.Checked;
Self.ProgressiveEncoding := chkProgressiveEncoding.Checked;
Self.Quality := StrToInt(edQuality.Text);
Self.PixelFormat := TPixelFormat(cmbPixelFormat.ItemIndex);
end;
finally
Free;
end;
end;
end;
end;
procedure TRMJPEGExport.OnEndPage;
var
JPEG: TJPEGImage;
BMP: TBitMap;
begin
JPEG := TJPEGImage.Create;
try
JPEG.Grayscale := FGrayscale;
JPEG.ProgressiveEncoding := FProgressiveEncoding;
JPEG.CompressionQuality := FQuality;
BMP := TBitmap.Create;
BMP.Width := FPageWidth;
BMP.Height := FPageHeight;
Bmp.PixelFormat := FPixelFormat;
DrawbkPicture(Bmp.Canvas);
CurReport.EMFPages.Draw(FPageNo, BMP.Canvas, Rect(0, 0, FPageWidth, FPageHeight));
JPEG.Assign(BMP);
JPEG.SaveToStream(Stream);
BMP.Free;
finally
JPEG.Free;
end;
inherited OnEndPage;
end;
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{TRMJPEGExportForm}
procedure TRMJPEGExportForm.Localize;
begin
Font.Name := RMLoadStr(SRMDefaultFontName);
Font.Size := StrToInt(RMLoadStr(SRMDefaultFontSize));
Font.Charset := StrToInt(RMLoadStr(SCharset));
RMSetStrProp(Self, 'Caption', rmRes + 1789);
RMSetStrProp(chkGrayscale, 'Caption', rmRes + 1812);
RMSetStrProp(chkProgressiveEncoding, 'Caption', rmRes + 1813);
RMSetStrProp(lblQuality, 'Caption', rmRes + 1814);
RMSetStrProp(lblQuality, 'Hint', rmRes + 1815);
RMSetStrProp(Label1, 'Caption', rmRes + 1806);
RMSetStrProp(Label4, 'Caption', rmRes + 1788);
btnOK.Caption := RMLoadStr(SOk);
btnCancel.Caption := RMLoadStr(SCancel);
end;
procedure TRMJPEGExportForm.FormCreate(Sender: TObject);
begin
Localize;
end;
procedure TRMJPEGExportForm.edQualityKeyPress(Sender: TObject;
var Key: Char);
begin
if not (Key in ['0'..'9', #8]) then
Key := #0;
end;
{$ENDIF}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -