From fa6f15ad9a8247e64dfeb003f62e60d66fbb2394 Mon Sep 17 00:00:00 2001 From: micha Date: Mon, 3 Jul 2006 12:58:28 +0000 Subject: [PATCH] preserve content when resizing bitmap (issue #1245) git-svn-id: trunk@9545 - --- lcl/include/bitmap.inc | 7 +++++-- lcl/intfgraphics.pas | 8 ++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lcl/include/bitmap.inc b/lcl/include/bitmap.inc index 6344c20e52..3bc9a48769 100644 --- a/lcl/include/bitmap.inc +++ b/lcl/include/bitmap.inc @@ -507,7 +507,7 @@ begin // copy content IntfImage:=TLazIntfImage.Create(0,0); try - IntfImage.LoadFromBitmap(FImage.FHandle,FImage.FMaskHandle); + IntfImage.LoadFromBitmap(FImage.FHandle,FImage.FMaskHandle,Width,Height); IntfImage.CreateBitmap(NewImage.FHandle,NewImage.FMaskHandle,false); FillChar(NewImage.FDIB, SizeOf(NewImage.FDIB), 0); if NewImage.HandleAllocated then @@ -643,7 +643,10 @@ begin if (FImage.FDIB.dsbm.bmHeight <> NewHeight) or (FImage.FDIB.dsbm.bmWidth <> NewWidth) then begin - FreeImage; + if (Width <> 0) and (Height <> 0) and (NewWidth <> 0) and (NewHeight <> 0) then + UnshareImage(true) + else + FreeImage; FImage.FDIB.dsbm.bmWidth := NewWidth; FImage.FDIB.dsbm.bmHeight := NewHeight; Changed(Self); diff --git a/lcl/intfgraphics.pas b/lcl/intfgraphics.pas index 78be3b4bc9..9a846077bd 100644 --- a/lcl/intfgraphics.pas +++ b/lcl/intfgraphics.pas @@ -182,7 +182,7 @@ type procedure GetDescriptionFromDevice(DC: HDC); virtual; procedure GetDescriptionFromBitmap(Bitmap: HBitmap); virtual; procedure LoadFromDevice(DC: HDC); virtual; - procedure LoadFromBitmap(Bitmap, MaskBitmap: HBitmap); virtual; + procedure LoadFromBitmap(Bitmap, MaskBitmap: HBitmap; AWidth: integer = -1; AHeight: integer = -1); virtual; procedure CreateBitmap(var Bitmap, MaskBitmap: HBitmap; AlwaysCreateMask: boolean); virtual; procedure SetRawImage(const RawImage: TRawImage); virtual; @@ -1678,7 +1678,7 @@ begin SetRawImage(ARawImage); end; -procedure TLazIntfImage.LoadFromBitmap(Bitmap, MaskBitmap: HBitmap); +procedure TLazIntfImage.LoadFromBitmap(Bitmap, MaskBitmap: HBitmap; AWidth, AHeight: integer); var ARect: TRect; ARawImage: TRawImage; @@ -1687,6 +1687,10 @@ begin if not GetBitmapRawImageDescription(Bitmap,@NewDataDescription) then raise FPImageException.Create('Failed to get raw image description from bitmap'); ARect:=Rect(0,0,NewDataDescription.Width,NewDataDescription.Height); + if (AWidth >= 0) and (dword(AWidth) < NewDataDescription.Width) then + ARect.Right := AWidth; + if (AHeight >= 0) and (dword(AHeight) > NewDataDescription.Height) then + ARect.Bottom := AHeight; if not GetRawImageFromBitmap(Bitmap,MaskBitmap,ARect,ARawImage) then raise FPImageException.Create('Failed to get raw image from bitmap'); SetRawImage(ARawImage);