Tokay Posted October 4, 2022 Share Posted October 4, 2022 Does it possible to fix loading of JPG image on the Linux? UniCanvas1.LoadFromFile(FileName); exception class EConvertError with message Cannot assign a TJPEGImage to a TUniBitmap Quote Link to comment Share on other sites More sharing options...
Tokay Posted October 4, 2022 Author Share Posted October 4, 2022 Also does exists any way to convert JPEG to BMP under Linux? Quote Link to comment Share on other sites More sharing options...
Tokay Posted October 17, 2022 Author Share Posted October 17, 2022 And change size of BMP or JPG? Quote Link to comment Share on other sites More sharing options...
Tokay Posted October 18, 2022 Author Share Posted October 18, 2022 Unexpectedly it turned out that FMX successfully works with UniGUI: uses FMX.Graphics, FMX.Surfaces; procedure TMainForm.UniButton1Click(Sender: TObject); var sp: TBitmapCodecSaveParams; bs: TBitmapSurface; B: TBitmap; begin B := TBitmap.Create; B.LoadFromFile('/home/user/Documents/test/123.bmp'); B.Resize(100, 100); B.SaveToFile('/home/user/Documents/test/out.bmp'); sp.Quality := 70; bs := TBitmapSurface.Create; bs.Assign(b); TBitmapCodecManager.SaveToFile('/home/user/Documents/test/out.jpg', bs, @sp); bs.Free; B.Free; end; This code change size of bmp and converts bmp to jpg file. 1 Quote Link to comment Share on other sites More sharing options...
Tokay Posted October 18, 2022 Author Share Posted October 18, 2022 For truth this code does not works on all Linux systems, gtk3 should be installed, but after installation works fine. Quote Link to comment Share on other sites More sharing options...
Tokay Posted October 19, 2022 Author Share Posted October 19, 2022 I've continue to find soultions for other Jpeg/Bitmap issues. This is converting function that works with UniGui, FMX: procedure ConvertJpgDoBmpStream(FileName: string; Stream: TMemoryStream); var Bitmap: TBitmap; bs: TBitmapSurface; begin Bitmap := TBitmap.Create; try Bitmap.LoadFromFile(FileName); bs := TBitmapSurface.Create; try bs.Assign(Bitmap); TBitmapCodecManager.SaveToStream(Stream, bs, 'bmp'); Stream.Position := 0; finally FreeAndNil(bs); end; finally FreeAndNil(Bitmap); end; end; It works fine, returns BMP, but UniCanvas couldnot load the BMP from the stream. Actually nothing just happens. I also check with loading BMP into the stream from the file and after try to open it UniCanvas1.LoadFromStream(Stream) but without success too. Linux, Ubuntu. Unfortunately we still does not have all the runtime UniGui code, TBitmap code does not exists in the installator and I could not find what is wrong. Farshad please fix the LoadFromStream! Quote Link to comment Share on other sites More sharing options...
Hayri ASLAN Posted October 20, 2022 Share Posted October 20, 2022 20 hours ago, Tokay said: I've continue to find soultions for other Jpeg/Bitmap issues. This is converting function that works with UniGui, FMX: procedure ConvertJpgDoBmpStream(FileName: string; Stream: TMemoryStream); var Bitmap: TBitmap; bs: TBitmapSurface; begin Bitmap := TBitmap.Create; try Bitmap.LoadFromFile(FileName); bs := TBitmapSurface.Create; try bs.Assign(Bitmap); TBitmapCodecManager.SaveToStream(Stream, bs, 'bmp'); Stream.Position := 0; finally FreeAndNil(bs); end; finally FreeAndNil(Bitmap); end; end; It works fine, returns BMP, but UniCanvas couldnot load the BMP from the stream. Actually nothing just happens. I also check with loading BMP into the stream from the file and after try to open it UniCanvas1.LoadFromStream(Stream) but without success too. Linux, Ubuntu. Unfortunately we still does not have all the runtime UniGui code, TBitmap code does not exists in the installator and I could not find what is wrong. Farshad please fix the LoadFromStream! Hello Is uniimage works with this conversion? Quote Link to comment Share on other sites More sharing options...
Tokay Posted October 20, 2022 Author Share Posted October 20, 2022 Is uniimage works with this conversion? Yes it is. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.