Recent

Author Topic: BGRABitmap "Unable to create file"  (Read 3637 times)

RedOctober

  • Sr. Member
  • ****
  • Posts: 402
BGRABitmap "Unable to create file"
« 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.]
                           
« Last Edit: June 10, 2021, 12:33:03 am by trev »

circular

  • Hero Member
  • *****
  • Posts: 3717
    • Personal webpage
Re: BGRABitmap "Unable to create file"
« Reply #1 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.
Conscience is the debugger of the mind

RedOctober

  • Sr. Member
  • ****
  • Posts: 402
Re: BGRABitmap "Unable to create file"
« Reply #2 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.  

winni

  • Hero Member
  • *****
  • Posts: 2519
Re: BGRABitmap "Unable to create file"
« Reply #3 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

RedOctober

  • Sr. Member
  • ****
  • Posts: 402
Re: BGRABitmap "Unable to create file"
« Reply #4 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.



winni

  • Hero Member
  • *****
  • Posts: 2519
Re: BGRABitmap "Unable to create file"
« Reply #5 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

circular

  • Hero Member
  • *****
  • Posts: 3717
    • Personal webpage
Re: BGRABitmap "Unable to create file"
« Reply #6 on: June 11, 2021, 07:03:10 am »
The suffix Inplace indicates that the change is done on the bitmap itself.
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018