Jump to content

Recommended Posts

Posted

Hello 

I set up for so user can upload a file and it works correctly. So if user uploads a jpg or bitmap, I use UniFileUploadCompleted:

procedure TfmTableEdit.UniFileUpload1Completed(Sender: TObject;
  AStream: TFileStream);
var
  aWinControl: TWinControl;
  blob: TStream;
  aField: TField;

begin
   //save to disk
   
    CopyFile(PChar(AStream.FileName), PChar(DestName), False); //overwrites.
    

   //place file in database field
   TBlobField(Self.MyQuery1.FieldByName( 'MyImage' ).LoadFromFile(DestName);


end;

Then I need to copy this image to another control:


            ms:=TMemoryStream.Create;
            with MyQuery.FieldByName('mImage') as TBlobField do
            begin
              Savetostream(ms);
              ms.Position:=0;
              aUniImage.Picture.Graphic.LoadFromStream(ms);
            end;


So if the original image is a Bitmap, it works perfectly. If the original image is a JPEG, it errors with:

EInvalidGraphic "Bitmap image is not valid"

Am I missing something? The controls usually figure out what type of format.

Thanks

Doug

 

  • Administrators
Posted

Hi,

Try this:

Image.LoadFromStream(Stream);

 

Graphics can only load image type of its own Type, so below code only works for file types which are sames as TGraphic object class type:

 

aUniImage.Picture.Graphic.LoadFromStream(ms);
  • Like 1
Posted
8 minutes ago, Farshad Mohajeri said:

Graphics can only load image type of its own Type, so below code only works for file types which are sames as TGraphic object class type:

 

Thank you Farshad, this worked perfectly !!!!

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...