FIX: Open with - crash when load not rectangle image

This commit is contained in:
Alexander Koblov 2019-04-14 12:23:13 +00:00
commit 86bebbcdd5
2 changed files with 27 additions and 3 deletions

View file

@ -81,7 +81,7 @@ implementation
uses
LCLProc, DCStrUtils, uOSUtils, uPixMapManager, uGlobs, uMimeActions,
uMimeType, uLng, LazUTF8, Math, uXdg;
uMimeType, uLng, LazUTF8, Math, uXdg, uGraphics;
const
CATEGORY_OTHER = 11; // 'Other' category index
@ -355,6 +355,7 @@ begin
Bitmap:= PixMapManager.GetBitmap(ImageIndex);
if Assigned(Bitmap) then
begin
BitmapCenter(Bitmap, ImageList.Width, ImageList.Height);
ANode.ImageIndex:= ImageList.Add(Bitmap, nil);
ANode.SelectedIndex:= ANode.ImageIndex;
ANode.StateIndex:= ANode.ImageIndex;

View file

@ -3,7 +3,7 @@
-------------------------------------------------------------------------
Graphic functions
Copyright (C) 2013-2017 Alexander Koblov (alexx2000@mail.ru)
Copyright (C) 2013-2019 Alexander Koblov (alexx2000@mail.ru)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@ -40,11 +40,12 @@ type
procedure BitmapAssign(Bitmap: TBitmap; Image: TRasterImage);
procedure BitmapAlpha(var ABitmap: TBitmap; APercent: Single);
procedure BitmapCenter(var Bitmap: TBitmap; Width, Height: Integer);
implementation
uses
GraphType, FPimage, IntfGraphics, uPixMapManager;
GraphType, FPimage, FPImgCanv, IntfGraphics, uPixMapManager;
type
TRawAccess = class(TRasterImage) end;
@ -83,6 +84,28 @@ begin
end;
end;
procedure BitmapCenter(var Bitmap: TBitmap; Width, Height: Integer);
var
X, Y: Integer;
Canvas: TFPImageCanvas;
Source, Target: TLazIntfImage;
begin
if (Bitmap.Width <> Width) or (Bitmap.Height <> Height) then
begin
Source:= Bitmap.CreateIntfImage;
Target:= TLazIntfImage.Create(Width, Height, [riqfRGB, riqfAlpha]);
Target.CreateData;
Canvas:= TFPImageCanvas.Create(Target);
X:= (Width - Bitmap.Width) div 2;
Y:= (Height - Bitmap.Height) div 2;
Canvas.Erase;
Canvas.Draw(X, Y, Source);
Bitmap.LoadFromIntfImage(Target);
Target.Free;
Source.Free;
end;
end;
{ TImageListHelper }
procedure TImageListHelper.LoadThemeIcon(Index: Integer; const AIconName: String);