Atozed Forums

Full Version: TIWImage
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Delphi has a TImage component. I use it like this:
...
    mPng.LoadFromStream(mStream2);
    Image1.Canvas.Draw(0,0,mPng);
...

IntraWeb has a TIWimage component, but it does not have a Canvas property. How to use it?
You are correct, there is no canvas in TIWImage.

If you need to draw directly to a canvas, you need fist to create a TBitmap instance, draw into the bitmap canvas and then assign the Bitmap to the TIWImage.Picture property.
The drawing is not displayed. Can you tell me what the problem is?

procedure TfmShowQRC.IWAppFormShow(Sender: TObject);
var
mStream1 : TMemoryStream;
mStream2 : TMemoryStream;
mPng : TPngobject;
mPicture : TPicture;
mBmp : TBitMap;
begin
mStream1 := TMemoryStream.Create;
mStream2 := TMemoryStream.Create;
mPng := TPNGObject.Create;
mBmp := TBitmap.Create;
try
mQRC := TestPictureBase64;
mStream1.WriteBuffer(mQRC[1],Length(mQRC)*SizeOf(Char));
mStream1.Position:=0;
DecodeStream(mStream1,mStream2);
mStream2.Position := 0;
mPng.LoadFromStream(mStream2);
mBmp.Canvas.Draw(0,0,mPng);
IWImage.Picture.Bitmap := mBmp;
finally
FreeAndNil(mStream1);
FreeAndNil(mStream2);
FreeAndNil(mPng);
FreeAndNil(mBmp);
end;
end;

And here is a working code for VCL:
procedure TfmViewQRC.FormShow(Sender: TObject);
var
mStream1 : TMemoryStream;
mStream2 : TMemoryStream;
mPng : TPngobject;
mBmp : TBitmap;
begin
mContent := TestPictureBase64;
mStream1 := TMemoryStream.Create;
mStream2 := TMemoryStream.Create;
mPng := TPNGObject.Create;
try
mStream1.WriteBuffer(mContent[1],Length(mContent)*SizeOf(Char));
mStream1.Position:=0;
DecodeStream(mStream1,mStream2);
mStream2.Position := 0;
mPng.LoadFromStream(mStream2);
Image1.Canvas.Draw(0,0,mPng);
finally
mStream1.Destroy;
mStream2.Destroy;
mPng.Destroy;
end;
end;
I think your problem is when you (don't) assign the bitmap to the picture.

The correct way to do it is via Assign() method of the picture, not setting the bitmap directly.

This simple code works correctly (I'm not using your Base64 encoded image, but the concept is exactly the same):

Code:
procedure TIWForm1.IWAppFormShow(Sender: TObject);
var
  mBmp : TBitMap;
begin
  mBmp := TBitmap.Create;
  try
    mBmp.Width := 200;
    mBmp.Height := 200;
    mBmp.Canvas.Brush.Color := clWhite;
    mBmp.Canvas.Pen.Color := clBlue;
    mBmp.Canvas.Rectangle(0, 0, 200, 200);
    mBmp.Canvas.MoveTo(0, 0);
    mBmp.Canvas.LineTo(200, 200);
    IWImage1.Picture.Assign(mBmp);
  finally
    FreeAndNil(mBmp);
  end;
end;