- workaround CreatePatterBrush (issue #0010735)
- few changes in createbitmap

git-svn-id: trunk@14160 -
This commit is contained in:
paul 2008-02-16 18:06:23 +00:00
parent 6c8377e7b0
commit d424e05321
2 changed files with 36 additions and 16 deletions

View File

@ -106,7 +106,8 @@ type
public
constructor Create;
constructor Create(vHandle: QImageH); overload;
constructor Create(Adata: PByte; width: Integer; height: Integer; format: QImageFormat; const ADataOwner: Boolean = False); overload;
constructor Create(AData: PByte; width: Integer; height: Integer; format: QImageFormat; const ADataOwner: Boolean = False); overload;
constructor Create(AData: PByte; width: Integer; height: Integer; bytesPerLine: Integer; format: QImageFormat; const ADataOwner: Boolean = False); overload;
destructor Destroy; override;
function AsIcon(AMode: QIconMode = QIconNormal; AState: QIconState = QIconOff): QIconH;
function AsPixmap(flags: QtImageConversionFlags = QtAutoColor): QPixmapH;
@ -873,10 +874,9 @@ end;
Contructor for the class.
------------------------------------------------------------------------------}
constructor TQtImage.Create(Adata: PByte; width: Integer; height: Integer;
constructor TQtImage.Create(AData: PByte; width: Integer; height: Integer;
format: QImageFormat; const ADataOwner: Boolean = False);
begin
FData := AData;
FDataOwner := ADataOwner;
@ -884,10 +884,18 @@ begin
Handle := QImage_create(width, height, format)
else
Handle := QImage_create(FData, width, height, format);
{$ifdef VerboseQt}
WriteLn('TQtImage.Create Result:', dbghex(PtrInt(Handle)));
{$endif}
end;
constructor TQtImage.Create(AData: PByte; width: Integer; height: Integer;
bytesPerLine: Integer; format: QImageFormat; const ADataOwner: Boolean);
begin
FData := AData;
FDataOwner := ADataOwner;
if FData = nil then
Handle := QImage_create(width, height, format)
else
Handle := QImage_create(FData, width, height, bytesPerLine, format);
end;
{------------------------------------------------------------------------------
@ -905,7 +913,7 @@ begin
if Handle <> nil then
QImage_destroy(Handle);
if (FDataOwner) and (FData <> nil) then
if (FDataOwner) and (FData <> nil) then
FreeMem(FData);
inherited Destroy;
@ -1250,8 +1258,18 @@ begin
end;
procedure TQtBrush.setTextureImage(image: QImageH);
var
TempImage: QImageH;
begin
QBrush_setTextureImage(Widget, image);
// workaround thurther deletion of original image
// When image is deleted its data will be deleted too
// If image has been created with predefined data then it will be owner of it
// => it will Free owned data => brush will be invalid
// as workaround we are copying an original image so qt create new image with own data
TempImage := QImage_create();
QImage_copy(image, TempImage, 0, 0, QImage_width(image), QImage_height(image));
QBrush_setTextureImage(Widget, TempImage);
QImage_destroy(TempImage);
end;
{ TQtPen }

View File

@ -325,7 +325,7 @@ function TQtWidgetSet.CreateBitmap(Width, Height: Integer;
Planes, BitCount: Longint; BitmapBits: Pointer): HBITMAP;
var
Format: QImageFormat;
NewBits: Pointer;
NewBits: PByte;
NewBitsSize: PtrUInt;
ARowStride, RSS: Integer;
begin
@ -353,18 +353,20 @@ begin
RSS := GetBytesPerLine(Width, BitCount, rileWordBoundary);
if BitmapBits <> nil then
begin
ARowStride := GetBytesPerLine(Width, BitCount, rileDWordBoundary);
if not CopyImageData(Width, Height, RSS, BitCount, BitmapBits, Rect(0, 0, Width, Height),
riloBottomToTop, riloBottomToTop, rileDWordBoundary, NewBits, NewBitsSize) then
begin
ARowStride := GetBytesPerLine(Width, BitCount, rileDWordBoundary);
NewBits := AllocMem(ARowStride);
Move(BitmapBits^, NewBits^, RSS);
// this was never tested
ARowStride := RSS;
NewBits := AllocMem(RSS * Height);
Move(BitmapBits^, NewBits^, RSS * Height);
end;
Result := HBitmap(TQtImage.Create(NewBits, Width, Height, ARowStride, Format, True));
end
else
NewBits := nil;
Result := HBitmap(TQtImage.Create(NewBits, Width, Height, Format, True));
Result := HBitmap(TQtImage.Create(nil, Width, Height, Format));
{$ifdef VerboseQtWinAPI}
WriteLn('Trace:< [WinAPI CreateBitmap] Bitmap:', dbghex(Result));
{$endif}