preserve content when resizing bitmap (issue #1245)

git-svn-id: trunk@9545 -
This commit is contained in:
micha 2006-07-03 12:58:28 +00:00
parent c9bcc3e061
commit fa6f15ad9a
2 changed files with 11 additions and 4 deletions

View File

@ -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);

View File

@ -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);