Jump to content

Loading JPG under linux


Tokay

Recommended Posts

  • 2 weeks later...

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.

  • Thanks 1
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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?

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