Jump to content

TUniCanvas BUG?


Ken Lewis

Recommended Posts

UniGUI 1555

var
  tmpStream : TMemoryStream;
begin
  ......
  TBlobField(FieldByName('li_image')).SaveToStream(tmpStream);
  tmpStream.Position :=0;
  UniCanvas1.Color := clWhite;
  UniCanvas1.Clear;
  uniCanvas1.LoadFromStream(tmpStream);  //When I use this ,the picture is not shown;
  tmpStream.SaveToFile(UniServerModule.StartPath +  'images/1.png');
  UniCanvas1.LoadFromFile(UniServerModule.StartPath +  'images/1.png');  //The picture is shown;
end;

 

Link to comment
Share on other sites

I don't see any creation of tmpStream...
Try this:
 

var
  tmpStream : TMemoryStream;
begin
  tmpStream:=TMemorystream.Create; 
  TRY
    TBlobField(FieldByName('li_image')).SaveToStream(tmpStream);
    tmpStream.Position :=0;
    UniCanvas1.Color := clWhite;
    UniCanvas1.Clear;
    uniCanvas1.LoadFromStream(tmpStream);  
  FINALLY
    FreeAndNil(tmpStream);
  END;
end;

 

Link to comment
Share on other sites

I only pasted the main part of the code, the part of the code you mentioned is actually there.

Design page:

3.png

Run page:  When I click btn1:
1.png
 

And when I click btn2:
2.png

Source Code:

procedure TSysParamFrm.btn1Click(Sender: TObject);
var
  tmpStream : TMemoryStream;
begin
  tmpStream:=TMemorystream.Create;
  try
    with qryGetImage do
    begin
      Close;
      Open;
      if not IsEmpty then
      begin
        TBlobField(FieldByName('li_image')).SaveToStream(tmpStream);
        tmpStream.Position :=0;
        UniCanvas1.Color := clWhite;
        UniCanvas1.Clear;
        uniCanvas1.LoadFromStream(tmpStream);
      end;
      Close;
    end;
  finally
    FreeAndNil(tmpStream);
  end;
end;

procedure TSysParamFrm.btn2Click(Sender: TObject);
var
  tmpStream : TMemoryStream;
begin
  tmpStream:=TMemorystream.Create;
  try
    with qryGetImage do
    begin
      Close;
      Open;
      if not IsEmpty then
      begin
        TBlobField(FieldByName('li_image')).SaveToStream(tmpStream);
        tmpStream.Position :=0;
        UniCanvas1.Color := clWhite;
        UniCanvas1.Clear;
        tmpStream.SaveToFile(UniServerModule.StartPath +  'images/1.png');
        UniCanvas1.LoadFromFile(UniServerModule.StartPath +  'images/1.png');
      end;
      Close;
    end;
  finally
    FreeAndNil(tmpStream);
  end;
end;

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...