diff --git a/components/jvcllaz/examples/JvThumbnail/JvThumbnailChildFormU.lfm b/components/jvcllaz/examples/JvThumbnail/JvThumbnailChildFormU.lfm index 778710f5b..0d7c22e65 100644 --- a/components/jvcllaz/examples/JvThumbnail/JvThumbnailChildFormU.lfm +++ b/components/jvcllaz/examples/JvThumbnail/JvThumbnailChildFormU.lfm @@ -31,14 +31,14 @@ object JvThumbnailChildForm: TJvThumbnailChildForm Cursor = crVSplit Left = 0 Height = 3 - Top = 124 + Top = 149 Width = 238 Align = alTop ResizeAnchor = akTop end object ShellTreeView: TShellTreeView Left = 4 - Height = 120 + Height = 145 Top = 4 Width = 230 Align = alTop @@ -60,8 +60,8 @@ object JvThumbnailChildForm: TJvThumbnailChildForm end object ShellListView: TShellListView Left = 4 - Height = 216 - Top = 150 + Height = 191 + Top = 175 Width = 230 Align = alClient BorderSpacing.Left = 4 @@ -244,15 +244,14 @@ object JvThumbnailChildForm: TJvThumbnailChildForm AnchorSideLeft.Control = Panel8 AnchorSideTop.Control = ContrastBar AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = Panel8 - AnchorSideRight.Side = asrBottom + AnchorSideRight.Control = CenterBevel Left = 4 Height = 25 Top = 205 - Width = 225 + Width = 107 + Anchors = [akTop, akLeft, akRight] BorderSpacing.Left = 4 BorderSpacing.Top = 2 - BorderSpacing.Right = 4 BorderSpacing.Bottom = 4 Caption = 'APPLY' OnClick = BtnApplyClick @@ -288,11 +287,27 @@ object JvThumbnailChildForm: TJvThumbnailChildForm Width = 16 Shape = bsSpacer end + object BtnSave: TButton + AnchorSideLeft.Control = CenterBevel + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = BtnApply + AnchorSideRight.Control = Panel8 + AnchorSideRight.Side = asrBottom + Left = 127 + Height = 25 + Top = 205 + Width = 107 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Right = 4 + Caption = 'SAVE' + OnClick = BtnSaveClick + TabOrder = 6 + end end object Panel10: TPanel Left = 4 Height = 23 - Top = 127 + Top = 152 Width = 230 Align = alTop AutoSize = True @@ -346,17 +361,16 @@ object JvThumbnailChildForm: TJvThumbnailChildForm AnchorSideLeft.Control = Panel1 AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = Panel5 - AnchorSideRight.Control = GbAngle AnchorSideRight.Side = asrBottom Left = 431 - Height = 82 + Height = 117 Top = 0 Width = 131 Anchors = [akTop, akLeft, akRight] AutoSize = True BorderSpacing.Left = 8 Caption = 'THUMBIMAGE' - ClientHeight = 62 + ClientHeight = 97 ClientWidth = 127 TabOrder = 0 object BtnInvert: TButton @@ -394,44 +408,33 @@ object JvThumbnailChildForm: TJvThumbnailChildForm OnClick = BtnGrayScaleClick TabOrder = 1 end - end - object GbAngle: TRadioGroup - AnchorSideLeft.Control = Panel1 - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = GbThumbImage - AnchorSideTop.Side = asrBottom - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = Panel1 - AnchorSideBottom.Side = asrBottom - Left = 431 - Height = 81 - Top = 94 - Width = 131 - Anchors = [akTop, akLeft, akBottom] - AutoFill = True - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Top = 12 - BorderSpacing.Right = 8 - Caption = ' ThumbImage Angle ' - ChildSizing.LeftRightSpacing = 16 - ChildSizing.EnlargeHorizontal = crsHomogenousChildResize - ChildSizing.EnlargeVertical = crsHomogenousChildResize - ChildSizing.ShrinkHorizontal = crsScaleChilds - ChildSizing.ShrinkVertical = crsScaleChilds - ChildSizing.Layout = cclLeftToRightThenTopToBottom - ChildSizing.ControlsPerLine = 2 - ClientHeight = 61 - ClientWidth = 127 - Columns = 2 - Items.Strings = ( - '0' - '90' - '180' - '270' - ) - OnClick = GbAngleClick - TabOrder = 1 + object CbTransform: TComboBox + AnchorSideLeft.Control = BtnInvert + AnchorSideTop.Control = BtnGrayScale + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = BtnInvert + AnchorSideRight.Side = asrBottom + Left = 8 + Height = 23 + Top = 62 + Width = 111 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Bottom = 12 + ItemHeight = 15 + ItemIndex = 0 + Items.Strings = ( + 'Rotate by 0°' + 'Rotate by 90°' + 'Rotate by 180°' + 'Rotate by 270°' + 'Mirror horizontally' + 'Mirror vertically' + ) + OnChange = CbTransformChange + Style = csDropDownList + TabOrder = 2 + Text = 'Rotate by 0°' + end end object ThumbNail: TJvThumbnail AnchorSideLeft.Control = Panel5 @@ -448,7 +451,7 @@ object JvThumbnailChildForm: TJvThumbnailChildForm ClientHeight = 175 ClientWidth = 152 Constraints.MinWidth = 152 - TabOrder = 2 + TabOrder = 1 OnClick = ThumbNailClick ShadowColor = clSilver TitleColor = clBtnFace @@ -468,7 +471,7 @@ object JvThumbnailChildForm: TJvThumbnailChildForm BevelOuter = bvLowered ClientHeight = 175 ClientWidth = 261 - TabOrder = 3 + TabOrder = 2 object CbAsButton: TCheckBox AnchorSideLeft.Control = Panel1 AnchorSideTop.Control = Panel1 @@ -597,23 +600,36 @@ object JvThumbnailChildForm: TJvThumbnailChildForm Height = 15 Hint = 'You can set the thumbnails title to what ever you want it to be ' Top = 123 - Width = 89 + Width = 84 BorderSpacing.Top = 9 BorderSpacing.Bottom = 4 - Caption = 'Thumbnails Title' + Caption = 'Thumbnail Title' ParentColor = False end object SpinEdit1: TSpinEdit + AnchorSideLeft.Control = LblMargin + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = BtnExit + AnchorSideTop.Side = asrCenter + Left = 60 + Height = 23 + Top = 90 + Width = 60 + BorderSpacing.Left = 12 + OnChange = SpinEdit1Change + TabOrder = 6 + end + object LblMargin: TLabel AnchorSideLeft.Control = Panel1 AnchorSideTop.Control = BtnExit AnchorSideTop.Side = asrCenter Left = 10 - Height = 23 - Top = 90 - Width = 86 + Height = 15 + Top = 94 + Width = 38 BorderSpacing.Left = 8 - OnChange = SpinEdit1Change - TabOrder = 6 + Caption = 'Margin' + ParentColor = False end end end diff --git a/components/jvcllaz/examples/JvThumbnail/JvThumbnailChildFormU.pas b/components/jvcllaz/examples/JvThumbnail/JvThumbnailChildFormU.pas index 9f4d1b02d..6b5201ebe 100644 --- a/components/jvcllaz/examples/JvThumbnail/JvThumbnailChildFormU.pas +++ b/components/jvcllaz/examples/JvThumbnail/JvThumbnailChildFormU.pas @@ -40,7 +40,10 @@ type { TJvThumbnailChildForm } TJvThumbnailChildForm = class(TForm) + BtnSave: TButton; CenterBevel: TBevel; + CbTransform: TComboBox; + LblMargin: TLabel; Panel1: TPanel; Panel2: TPanel; SpinEdit1: TSpinEdit; @@ -75,18 +78,18 @@ type LblLightness: TLabel; LightnessBar: TTrackBar; BtnExit: TButton; - GbAngle: TRadioGroup; ThumbNail: TJVThumbNail; ThumbImage: TJvThumbImage; procedure BtnApplyClick(Sender: TObject); procedure BtnInvertClick(Sender: TObject); procedure BtnGrayScaleClick(Sender: TObject); + procedure BtnSaveClick(Sender: TObject); procedure CbAsButtonClick(Sender: TObject); procedure CbAutoLoadClick(Sender: TObject); procedure CbMinimizeMemClick(Sender: TObject); + procedure CbTransformChange(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormShow(Sender: TObject); - procedure GbAngleClick(Sender: TObject); procedure GbTitlePlacementClick(Sender: TObject); procedure Panel10Resize(Sender: TObject); procedure Panel2Resize(Sender: TObject); @@ -130,6 +133,7 @@ begin BlueBar.Position := 0; ContrastBar.Position := 0; LightnessBar.Position := 0; + BtnSave.Enabled := true; end; procedure TJvThumbnailChildForm.LoadFile(const AFileName: String); @@ -241,6 +245,25 @@ begin ThumbNail.MinimizeMemory := CbMinimizeMem.Checked; end; +procedure TJvThumbnailChildForm.CbTransformChange(Sender: TObject); +var + w, h: Integer; +begin + w := ThumbImage.Picture.Width; + h := ThumbImage.Picture.Height; + case CbTransform.ItemIndex of + 0: ThumbImage.Angle := AT0; + 1: ThumbImage.Angle := AT90; + 2: ThumbImage.Angle := AT180; + 3: ThumbImage.Angle := AT270; + 4: ThumbImage.Mirror(mtHorizontal); + 5: ThumbImage.Mirror(mtVertical); + end; + if (w <> ThumbImage.Picture.Width) or (h <> ThumbImage.Picture.Height) then + with ThumbImage do SetBounds(0, 0, Picture.Width, Picture.Height); + BtnSave.Enabled := true; +end; + procedure TJvThumbnailChildForm.FormCreate(Sender: TObject); begin {$IFDEF WINDOWS} @@ -249,6 +272,7 @@ begin {$ENDIF} FilterCombobox.ItemIndex := 0; ShellListView.Mask := FilterCombobox.Mask; + BtnSave.Enabled := false; end; procedure TJvThumbnailChildForm.GbTitlePlacementClick(Sender: TObject); @@ -264,11 +288,23 @@ end; procedure TJvThumbnailChildForm.BtnInvertClick(Sender: TObject); begin ThumbImage.Invert; + BtnSave.Enabled := true; end; procedure TJvThumbnailChildForm.BtnGrayScaleClick(Sender: TObject); begin ThumbImage.GrayScale; + BtnSave.Enabled := true; +end; + +procedure TJvThumbnailChildForm.BtnSaveClick(Sender: TObject); +var + fn: String; +begin + if ThumbImage.Modified then begin + fn := ChangeFileExt(ThumbImage.FileName, '') + '_modified' + ExtractFileExt(ThumbImage.FileName); + ThumbImage.SaveToFile(fn); + end; end; procedure TJvThumbnailChildForm.ThumbNailClick(Sender: TObject); @@ -299,23 +335,11 @@ end; procedure TJvThumbnailChildForm.FormShow(Sender: TObject); begin - //ThumbImage.Picture.Free; GbTitlePlacement.ItemIndex := integer(ThumbNail.titlePlacement); - GbAngle.ItemIndex := integer(ThumbImage.angle); + CbTransform.ItemIndex := 0; SpinEdit1.Value := Thumbnail.Margin; end; -procedure TJvThumbnailChildForm.GbAngleClick(Sender: TObject); -var - w, h: Integer; -begin - w := ThumbImage.Picture.Width; - h := ThumbImage.Picture.Height; - ThumbImage.Angle := TAngle(GbAngle.ItemIndex); - if (w <> ThumbImage.Picture.Width) or (h <> ThumbImage.Picture.Height) then - with ThumbImage do SetBounds(0, 0, Picture.Width, Picture.Height); -end; - function TJvThumbnailChildForm.GetfileName: String; begin Result := ShellListView.GetPathFromItem(ShellListView.Selected); diff --git a/components/jvcllaz/run/JvCustomControls/JvBaseThumbnail.pas b/components/jvcllaz/run/JvCustomControls/JvBaseThumbnail.pas index b259cf93f..be9374740 100644 --- a/components/jvcllaz/run/JvCustomControls/JvBaseThumbnail.pas +++ b/components/jvcllaz/run/JvCustomControls/JvBaseThumbnail.pas @@ -137,6 +137,8 @@ type private FIgnoreMouse: Boolean; protected + procedure Click; override; + procedure DblClick; override; { wp removed function HitTest(X, Y: Integer): Boolean; override; } procedure MouseDown(Button: TMouseButton; Shift: TShiftState; @@ -144,8 +146,6 @@ type procedure MouseMove(Shift: TShiftState; X, Y: Integer); override; procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; - procedure Click; override; - procedure DblClick; override; public constructor Create(AOwner: TComponent); override; published diff --git a/components/jvcllaz/run/JvCustomControls/JvThumbImage.pas b/components/jvcllaz/run/JvCustomControls/JvThumbImage.pas index 7625714f5..7387a5fba 100644 --- a/components/jvcllaz/run/JvCustomControls/JvThumbImage.pas +++ b/components/jvcllaz/run/JvCustomControls/JvThumbImage.pas @@ -63,7 +63,10 @@ type TFilterEmpty = function: Byte; TFilterArray = array [1..9] of Byte; - TJvTransformProc = procedure (ASourceIntfImage, ADestIntfImage: TLazIntfImage; + TJvTransformProc = procedure (AIntfImage: TLazIntfImage; + ARedData, AGreenData, ABlueData: Pointer); + + TJvTransformProc2 = procedure (ASourceIntfImage, ADestIntfImage: TLazIntfImage; ARedData, AGreenData, ABlueData: Pointer); { TJvThumbImage } @@ -78,8 +81,6 @@ type FFileName: string; FClass: TGraphicClass; FOnInvalidImage: TInvalidImageEvent; -// procedure Rotate90; -// procedure Rotate270; procedure SetAngle(AAngle: TAngle); function GetModify: Boolean; public @@ -95,7 +96,9 @@ type procedure SaveToFile(AFile: string); procedure Save; procedure Transform(TransformProc: TJvTransformProc; ARedData: Pointer = nil; - AGreenData: Pointer = nil; ABlueData: Pointer = nil); + AGreenData: Pointer = nil; ABlueData: Pointer = nil); overload; + procedure Transform(TransformProc: TJvTransformProc2; ARedData: Pointer = nil; + AGreenData: Pointer = nil; ABlueData: Pointer = nil); overload; procedure BitmapNeeded; // Procedure FilterFactory(Filter: TFilterArray; Divider: Byte); procedure Invert; @@ -104,6 +107,7 @@ type procedure Grayscale; procedure Rotate(AAngle: TAngle); function GetFilter: string; + property FileName: String read FFileName; //property JpegScale: TJPegScale read vJPegScale write vJpegScale; published property Angle: TAngle read FAngle write SetAngle; @@ -124,64 +128,66 @@ uses FPImage, JvThumbnails, JvTypes, JvResources; -procedure GrayScaleProc(ASrcImg, ADestImg: TLazIntfImage; - ARedData, AGreenData, ABlueData: Pointer); +procedure GrayScaleProc(AImg: TLazIntfImage; ARedData, AGreenData, ABlueData: Pointer); var r, c: Integer; clr: TColor; col: TFPColor; intens: Integer; begin - for r := 0 to ASrcImg.Height - 1 do - for c := 0 to ASrcImg.Width - 1 do begin - col := ASrcImg.Colors[c, r]; + for r := 0 to AImg.Height - 1 do + for c := 0 to AImg.Width - 1 do begin + col := AImg.Colors[c, r]; intens := (integer(col.Red) + col.Green + col.Blue) div 3; - ADestImg.Colors[c, r] := FPColor(intens, intens, intens, col.Alpha); + AImg.Colors[c, r] := FPColor(intens, intens, intens, col.Alpha); end; end; -procedure InvertProc(ASrcImg, ADestImg: TLazIntfImage; - ARedData, AGreenData, ABlueData: Pointer); +procedure InvertProc(AImg: TLazIntfImage; ARedData, AGreenData, ABlueData: Pointer); +const + MX: word = $FFFF; var r, c: Integer; col: TFPColor; a: Word; begin - for r := 0 to ASrcImg.Height - 1 do - for c := 0 to ASrcImg.Width - 1 do begin - col := ASrcImg.Colors[c, r]; + for r := 0 to AImg.Height - 1 do + for c := 0 to AImg.Width - 1 do begin + col := AImg.Colors[c, r]; a := col.Alpha; - ADestImg.Colors[c, r] := FPColor(word(-col.Red), word(-col.Green), word(-col.Blue), a); + AImg.Colors[c, r] := FPColor(MX-col.Red, MX-col.Green, MX-col.Blue, a); end; end; -procedure MirrorHorProc(ASrcImg, ADestImg: TLazIntfImage; - ARedData, AGreenData, ABlueData: Pointer); +procedure MirrorHorProc(AImg: TLazIntfImage; ARedData, AGreenData, ABlueData: Pointer); var r, c, w, h: Integer; - col: TFPColor; + col1, col2: TFPColor; begin - w := ASrcImg.Width; - h := ASrcImg.Height; + w := AImg.Width; + h := AImg.Height; for r := 0 to h - 1 do - for c := 0 to w - 1 do begin - col := ASrcImg.Colors[c, r]; - ADestImg.Colors[w-1-c, r] := col; + for c := 0 to w div 2 do begin + col1 := AImg.Colors[c, r]; + col2 := AImg.Colors[w-1-c, r]; + AImg.Colors[c, r] := col2; + AImg.Colors[w-1-c, r] := col1; end; end; -procedure MirrorVertProc(ASrcImg, ADestImg: TLazIntfImage; - ARedData, AGreenData, ABlueData: Pointer); +procedure MirrorVertProc(AImg: TLazIntfImage; ARedData, AGreenData, ABlueData: Pointer); var r, c, w, h: Integer; - col: TFPColor; + col1, col2: TFPColor; begin - w := ASrcImg.Width; - h := ASrcImg.Height; - for r := 0 to h - 1 do - for c := 0 to w - 1 do begin - col := ASrcImg.Colors[c, r]; - ADestImg.Colors[c, h-1-r] := col; + w := AImg.Width; + h := AImg.Height; + for c := 0 to w - 1 do + for r := 0 to h div 2 do begin + col1 := AImg.Colors[c, r]; + col2 := AImg.Colors[c, h-1-r]; + AImg.Colors[c, r] := col2; + AImg.Colors[c, h-1-r] := col1; end; end; @@ -209,7 +215,6 @@ var begin w := ASrcImg.Width; h := ASrcImg.Height; - ADestImg.SetSize(h, w); for r := 0 to h - 1 do for c := 0 to w - 1 do begin col := ASrcImg.Colors[c, r]; @@ -233,8 +238,7 @@ begin end; end; -procedure RGBProc(ASrcImg, ADestImg: TLazIntfImage; - ARedData, AGreenData, ABlueData: Pointer); +procedure RGBProc(AImg: TLazIntfImage; ARedData, AGreenData, ABlueData: Pointer); var r, c: Integer; clr: TColor; @@ -246,21 +250,19 @@ begin deltaR := PtrUInt(ARedData); deltaG := PtrUInt(AGreenData); deltaB := PtrUInt(ABlueData); - for r := 0 to ASrcImg.Height - 1 do - for c := 0 to ASrcImg.Width - 1 do begin - a := ASrcImg.Colors[c, r].Alpha; - clr := ASrcImg.TColors[c, r]; + for r := 0 to AImg.Height - 1 do + for c := 0 to AImg.Width - 1 do begin + a := AImg.Colors[c, r].Alpha; + clr := AImg.TColors[c, r]; rVal := BoundByte(0, 255, GetBValue(clr) + deltaR); gVal := BoundByte(0, 255, GetGValue(clr) + deltaG); bVal := BoundByte(0, 255, GetBValue(clr) + deltaB); col := FPColor(rval shl 8, gval shl 8, bval shl 8, a); - ADestImg.Colors[c, r] := col; -// ADestImg.TColors[c, r] := RGBToColor(rVal, gVal, bVal); + AImg.Colors[c, r] := col; end; end; -procedure RGBCurveProc(ASrcImg, ADestImg: TLazIntfImage; - ARedData, AGreenData, ABlueData: Pointer); +procedure RGBCurveProc(AImg: TLazIntfImage; ARedData, AGreenData, ABlueData: Pointer); var r, c: Integer; clr: TColor; @@ -268,16 +270,15 @@ var a: Word; col: TFPColor; begin - for r := 0 to ASrcImg.Height - 1 do - for c := 0 to ASrcImg.Width - 1 do begin - a := ASrcImg.Colors[c, r].Alpha; - clr := ASrcImg.TColors[c, r]; + for r := 0 to AImg.Height - 1 do + for c := 0 to AImg.Width - 1 do begin + a := AImg.Colors[c, r].Alpha; + clr := AImg.TColors[c, r]; rVal := TCurveArray(ARedData^)[GetRValue(clr)]; gVal := TCurveArray(AGreenData^)[GetGValue(clr)]; bVal := TCurveArray(ABlueData^)[GetBValue(clr)]; col := FPColor(rVal shl 8, gVal shl 8, bVal shl 8, a); - ADestImg.Colors[c, r] := col; - //ADestImg.TColors[c, r] := RGBToColor(rVal, gVal, bVal); + AImg.Colors[c, r] := col; end; end; @@ -552,13 +553,14 @@ var Ext: string; Jpg: TJpegImage; Bmp: TBitmap; + png: TPortableNetworkGraphic; {*************** NOT CONVERTED *** Wmf: TMetafile; ********************************} begin // (rom) enforcing a file extension is bad style - Ext := UpperCase(ExtractFileExt(AFile)); - if (Ext = '.JPG') or (Ext = '.JPEG') then + Ext := LowerCase(ExtractFileExt(AFile)); + if (Ext = '.jpg') or (Ext = '.jpeg') then try Jpg := TJpegImage.Create; Jpg.Assign(Picture.Graphic); @@ -568,18 +570,28 @@ begin **********************************} Jpg.SaveToFile(AFile); finally - FreeAndNil(Jpg); + Jpg.Free; end else - if Ext = '.BMP' then + if Ext = '.bmp' then try Bmp := Graphics.TBitmap.Create; Bmp.Assign(Picture.Graphic); Bmp.Canvas.Draw(0, 0, Picture.Graphic); Bmp.SaveToFile(AFile); finally - FreeAndNil(Bmp); - end + Bmp.Free; + end + else + if Ext = '.png' then + try + png := TPortableNetworkGraphic.Create; + png.Assign(Picture.Graphic); + png.Canvas.Draw(0, 0, Picture.Graphic); + png.SaveToFile(AFile); + finally + png.Free; + end { ********************** NOT CONVERTED *** else if Ext = '.WMF' then @@ -783,61 +795,43 @@ end; procedure TJvThumbImage.Transform(TransformProc: TJvTransformProc; ARedData: Pointer = nil; AGreenData: Pointer = nil; ABlueData: Pointer = nil); var - Bmp: TBitmap; + IntfImg: TLazIntfImage; + ImgHandle, ImgMaskHandle: HBitmap; +begin + if Assigned(Picture.Graphic) and CanModify then begin + IntfImg := TPortableNetworkGraphic(Picture.Graphic).CreateIntfImage; + try + TransformProc(IntfImg, ARedData, AGreenData, ABlueData); + IntfImg.CreateBitmaps(ImgHandle, ImgMaskHandle); + Picture.Bitmap.LoadFromIntfImage(IntfImg); + FModified := true; + finally + IntfImg.Free; + end; + end; +end; + +{ General bitmap transformation method using LazIntfImages. The operation is + specified by the procedure pointer TransformProc. } +procedure TJvThumbImage.Transform(TransformProc: TJvTransformProc2; + ARedData: Pointer = nil; AGreenData: Pointer = nil; ABlueData: Pointer = nil); +var SrcIntfImg, DestIntfImg: TLazIntfImage; DestImgHandle, DestImgMaskHandle: HBitmap; - w, h: Integer; begin - if Assigned(Picture.Graphic) then - if CanModify then - begin - w := Picture.Width; - h := Picture.Height; - SrcIntfImg := TLazIntfImage.Create(0, 0); - DestIntfImg := TLazIntfImage.Create(0, 0); - if Picture.Graphic is TPortableNetworkGraphic then - begin - SrcIntfImg := TPortableNetworkGraphic(Picture.Graphic).CreateIntfImage; - DestIntfImg := TPortableNetworkGraphic(Picture.Graphic).CreateIntfImage; - TransformProc(SrcIntfImg, DestIntfImg, ARedData, AGreenData, ABlueData); - DestIntfImg.CreateBitmaps(DestImgHandle, DestImgMaskHandle); - bmp := TBitmap.Create; - bmp.SetSize(DestIntfImg.Width, DestIntfImg.Height); - bmp.Canvas.Brush.Color := clWhite; - bmp.Canvas.FillRect(0, 0, 1, 1); - bmp.Handle := DestImgHandle; - bmp.MaskHandle := DestImgMaskHandle; - Picture.Graphic.Clear; - TPortableNetworkGraphic(Picture.Graphic).Assign(bmp); - Invalidate; - bmp.Free; - DestIntfImg.Free; - SrcIntfImg.Free; - end else - begin - Bmp := TBitmap.Create; - Bmp.PixelFormat := pf32bit; - Bmp.SetSize(w, h); - Bmp.Canvas.Brush.Color := clWhite; - Bmp.Canvas.FillRect(0, 0, w, h); - Bmp.Assign(Picture.Graphic); - SrcIntfImg.LoadFromBitmap(Bmp.Handle, Bmp.MaskHandle); - DestIntfImg.LoadFromBitmap(Bmp.Handle, Bmp.MaskHandle); - TransformProc(SrcIntfImg, DestIntfImg, ARedData, AGreenData, ABlueData); - DestIntfImg.CreateBitmaps(DestImgHandle, DestImgMaskHandle); - Bmp.Handle := DestImgHandle; - Bmp.MaskHandle := DestImgMaskHandle; - Picture.Graphic.Clear; - if Picture.Graphic is TJpegImage then - TJpegImage(Picture.Graphic).Assign(Bmp) - else if Picture.Graphic is Graphics.TBitmap then - Picture.Bitmap.Assign(Bmp); - Invalidate; - Bmp.Free; - SrcIntfImg.Free; - DestIntfImg.Free; - end; + if Assigned(Picture.Graphic) and CanModify then begin + SrcIntfImg := TPortableNetworkGraphic(Picture.Graphic).CreateIntfImage; + DestIntfImg := TPortableNetworkGraphic(Picture.Graphic).CreateIntfImage; + try + TransformProc(SrcIntfImg, DestIntfImg, ARedData, AGreenData, ABlueData); + DestIntfImg.CreateBitmaps(DestImgHandle, DestImgMaskHandle); + Picture.Bitmap.LoadFromIntfImage(DestIntfImg); + FModified := true; + finally + DestIntfImg.Free; + SrcIntfImg.Free; end; + end; end; { Procedure to actually decide what should be the rotation in conjuction with the