Lazarus

Programming => Graphics => Graphics and Multimedia => BGRABitmap and LazPaint => Topic started by: RedOctober on June 09, 2021, 11:58:39 pm

Title: BGRABitmap "Unable to create file"
Post by: RedOctober on June 09, 2021, 11:58:39 pm
I'm doing a rotate of a .jpg photograph as follows, but about 20% of the time, this routing displays an "Unable to create file" error message.  What's weird, is that, if I open the .jpg file in MS Paint, the image is indeed rotated.

Code: Pascal  [Select][+][-]
  1. procedure GrabItRotate(const src_fnm: String; const dgr: Integer);
  2. var bmp: TBGRABitmap;
  3. begin
  4.   bmp := TBGRABitmap.Create(src_fnm);
  5.  
  6.   case dgr of
  7.      90:begin
  8.           BGRAReplace(bmp, bmp.RotateCW);
  9.         end;
  10.     180:begin
  11.           bmp.HorizontalFlip;
  12.           bmp.VerticalFlip;
  13.         end;
  14.     270:begin
  15.           BGRAReplace(bmp, bmp.RotateCCW);
  16.         end;
  17.   end;
  18.  
  19.   bmp.SaveToFile(src_fnm);
  20.   bmp.Free;
  21. end;

[Edited to add code tags - PLEASE read How to use the Forums (https://wiki.lazarus.freepascal.org/Forum).]
                           
Title: Re: BGRABitmap "Unable to create file"
Post by: circular on June 10, 2021, 01:59:32 pm
I wonder if the image is not locked by another program.

Note that you can use RotateUDInplace for 180-degree rotation.
Title: Re: BGRABitmap "Unable to create file"
Post by: RedOctober on June 10, 2021, 03:46:14 pm
Hi Circular, what is the correct syntax for RotateUDInplace ?

This won't compile...

Code: Pascal  [Select][+][-]
  1.   BGRAReplace(bmp, bmp.RotateUDInplace);
  2.  
Title: Re: BGRABitmap "Unable to create file"
Post by: winni on June 10, 2021, 06:28:36 pm
Hi!

Place the cursor on RotateUDInplace
Press Ctrl-CursorUp

You get the Interface definition of RotateUDInplace.
You see that it is a procedure with no params.

So the correct syntax is

Code: Pascal  [Select][+][-]
  1. bmp.RotateUDInplace;
  2.  

Not such a hard job to do that!?

Winni
Title: Re: BGRABitmap "Unable to create file"
Post by: RedOctober on June 10, 2021, 08:39:33 pm
Hi Winni,

I used the wrong term.  I shd not have said "syntax".

You see in my example, I am doing a BGRAReplace()... the other two rotates compile, but the 

BGRAReplace(bmp, bmp.RotateUDInplace);

will not.

I guess my question shd be, what is the proper way to call the .RotateUDInplace so that it replaces the bmp.


Title: Re: BGRABitmap "Unable to create file"
Post by: winni on June 10, 2021, 09:07:19 pm
Hi Winni,

I used the wrong term.  I shd not have said "syntax".

You see in my example, I am doing a BGRAReplace()... the other two rotates compile, but the 

BGRAReplace(bmp, bmp.RotateUDInplace);

will not.

I guess my question shd be, what is the proper way to call the .RotateUDInplace so that it replaces the bmp.

Heeehh - RotateUDInplace is a procedure and NOT a function.
There is no function result - so BGRAreplace HAS TO crash!!!

Code: Pascal  [Select][+][-]
  1. var tmp: TBGRAbitmap;
  2. ...
  3. tmp := TBGRAbitmap.create(bmp);
  4. tmp.RotateUDInplace;
  5. // now use tmp
  6. tmp.free;
  7.  


Winni
Title: Re: BGRABitmap "Unable to create file"
Post by: circular on June 11, 2021, 07:03:10 am
The suffix Inplace indicates that the change is done on the bitmap itself.
TinyPortal © 2005-2018