拿钱来!!!!!!!
unit TJpgImg;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, jpeg;
type
TFEJpeg = class;
TJPEGChangeEvent= procedure (Val : Byte) of object;
TJPEGProperties = Class(TPersistent)
private
FGrayScale : Boolean;
FPixelFormat : TJPEGPixelFormat;
FProgressiveDisplay : Boolean;
FPerformance : TJPEGPerformance;
FScale : TJPEGScale;
FSmoothing : Boolean;
FOnChange: TJPEGChangeEvent;
protected
procedure SetGrayScale(Value : Boolean);
procedure SetPixelFormat(Value : TJPEGPixelFormat);
procedure SetProgressiveDisplay(Value : Boolean);
procedure SetPerformance(Value : TJPEGPerformance );
procedure SetScale(Value : TJPEGScale);
procedure SetSmoothing(Value : Boolean);
public
constructor Create;
procedure Change(Val : Byte);
published
property GrayScale : Boolean REad FGrayScale write SetGrayScale;
property PixelFormat : TJPEGPixelFormat read FPixelFormat write SetPixelFormat;
property ProgressiveDisplay : Boolean read FProgressiveDisplay write SetProgressiveDisplay;
property Performance : TJPEGPerformance read FPerformance write SetPerformance;
property Scale : TJPEGScale read FScale write SetScale;
property Smoothing : Boolean Read FSmoothing write SetSmoothing;
property OnChange : TJPEGChangeEvent read FOnChange write FOnChange;
end;
TFEJpeg = class(TImage)
private
FExit : Boolean;
FDrawing : boolean;
FJPEGProperties : TJpegProperties;
FOldChanged : TNotifyEvent;
FOnMouseIn:TNotifyEvent;
FOnMouseOut:TNotifyEvent;
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
procedure PictureChanged(Sender : TObject);
procedure UpdateJPEG(Flag : Byte);
public
procedure Paint;override;
constructor create(AOwner : TComponent);override;
destructor Destroy;override;
procedure UpdateImage;
published
property JPEGProperties : TJPEGProperties read FJPEGProperties write FJPEGProperties;
property OnMouseIn: TNotifyEvent read FOnMouseIn write FOnMouseIn;
property OnMouseOut: TNotifyEvent read FOnMouseOut write FOnMouseOut;
end;
procedure Register;
implementation
constructor TJPEGProperties.Create;
begin
inherited Create;
FGrayScale := false;
FPixelFormat := jf24Bit;
FProgressiveDisplay := false;
FPerformance := jpBestQuality;
FScale := jsFullSize;
FSmoothing := true;
end;
procedure TJPEGProperties.Change(Val : Byte);
begin
if Assigned(OnChange) then OnChange(val);
end;
procedure TJPEGProperties.SetGrayScale(Value : Boolean);
begin
if Value <> FGrayScale then
begin
FGrayScale := Value;
Change(1);
end;
end;
procedure TJPEGProperties.SetPixelFormat(Value : TJPEGPixelFormat);
begin
if Value <> FPixelFormat then
begin
FPixelFormat := Value;
Change(2);
end;
end;
procedure TJPEGProperties.SetProgressiveDisplay(Value : Boolean);
begin
if Value <> FProgressiveDisplay then
begin
FProgressiveDisplay := Value;
Change(3);
end;
end;
procedure TJPEGProperties.SetPerformance(Value : TJPEGPerformance );
begin
if Value <> FPerformance then
begin
FPerformance := Value;
Change(4);
end;
end;
procedure TJPEGProperties.SetScale(Value : TJPEGScale);
begin
if Value <> FScale then
begin
FScale := Value;
Change(5);
end;
end;
procedure TJPEGProperties.SetSmoothing(Value : Boolean);
begin
if Value <> FSmoothing then
begin
FSmoothing := Value;
Change(6);
end;
end;
// TJpeg
procedure TFEJpeg.CMMouseEnter(var Message: TMessage);
begin
inherited;
if Assigned(FOnMouseIn) then FOnMouseIn(Self);
end;
procedure TFEJpeg.CMMouseLeave(var Message: TMessage);
begin
inherited;
if Assigned(FOnMouseIn) then FOnMouseOut(Self);
end;
procedure TFEJpeg.Paint;
begin
FDrawing := true;
inherited Paint;
FDrawing := false;
end;
constructor TFEJpeg.create(AOwner : TComponent);
begin
inherited create(AOwner);
FJPEGProperties := TJPEGProperties.Create;
FJPEGProperties.OnChange := UpdateJPEG;
FExit := false;
FDrawing := false;
FOldChanged := Picture.OnChange;
Picture.OnChange := PictureChanged;
end;
destructor TFEJpeg.Destroy;
begin
Picture.OnChange := nil;
FOldChanged := nil;
FJPEGProperties.Free;
inherited Destroy;
end;
procedure TFEJpeg.PictureChanged(Sender : TObject);
begin
if FExit then EXIT;
if Picture.Graphic is TJPEGImage then with TJPEGImage(Picture.Graphic) do
begin
FEXit := true;
PixelFormat := FJPEGProperties.PixelFormat;
Scale := FJPEGProperties.Scale;
Grayscale := FJPEGProperties.GrayScale;
Performance := FJPEGProperties.Performance;
ProgressiveDisplay := FJPEGProperties.ProgressiveDisplay;
Smoothing := FJPEGProperties.Smoothing;
FEXit := false;
end;
if Assigned(FOldChanged) then FOldChanged(Sender);
end;
procedure TFEJpeg.UpdateJPEG(Flag : Byte);
begin
if Picture.Graphic is TJPEGImage then with TJPEGImage(Picture.Graphic) do
begin
case Flag of
1 : Grayscale := FJPEGProperties.GrayScale;
2 : PixelFormat := FJPEGProperties.PixelFormat;
3 : ProgressiveDisplay := FJPEGProperties.ProgressiveDisplay;
4 : Performance := FJPEGProperties.Performance;
5 : Scale := FJPEGProperties.Scale;
6 : Smoothing := FJPEGProperties.Smoothing;
end;
if Flag <> 3 then if Assigned(FOldChanged) then FOldChanged(Picture);
end;
end;
procedure TFEJpeg.UpdateImage;
begin
if Picture.Graphic is TJPEGImage then with TJPEGImage(Picture.Graphic) do
begin
Grayscale := FJPEGProperties.GrayScale;
PixelFormat := FJPEGProperties.PixelFormat;
ProgressiveDisplay := FJPEGProperties.ProgressiveDisplay;
Performance := FJPEGProperties.Performance;
Scale := FJPEGProperties.Scale;
Smoothing := FJPEGProperties.Smoothing;
end;
end;
procedure Register;
begin
RegisterComponents('JpgImg', [TFEJpeg]);
end;
end.