iOS Question Bitmap Rotate, Resize and orientation

Semen Matusovskiy

Well-Known Member
Licensed User
Hi, guys --

The webserver does not want to process EXIF DATA, so in B4A I rotated photos and corrected EXIF DATA using libraries. Now need to do the same in B4i.

I took a photo with landscape orientation (4608 * 3456) from Android smartphone.
Internally pixeles are stored in portrait order and "orientation" in EXIF is set to 90 degrees CW. All "normal" Windows programs show this JPG file correctly.

In B4i I retrieved the orientation from Bitmap using GetField ("imageOrientation") and expected that I need to rotate 90 or 270 degrees. No, this does not work.

Alone variant, which I found, to show a photo in imageview correctly was imageview.bitmap = bitmap.Rotate (0).

Ok, if IOS calculates so, not a problem. The problem is another. B4i reports that rotated bitmap has the same size, as an original bitmap (width = 3456, height = 4608) instead of expected 4608 * 3456 and this is a serious trouble.

Any ideas ?

Semen Matusovskiy

Well-Known Member
Licensed User
Thanks to stackoverflow I, probably, found a solution.
The following subroutine, as I understood comments, makes a copy of bitmap, but without orientation.
 - (UIImage*) removeOrientation:(UIImage*) image
    CGSize size = image.size;
    UIGraphicsBeginImageContext (size);
    [image drawInRect:CGRectMake (0, 0, size.width, size.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext ();
    UIGraphicsEndImageContext ();
    return newImage;
With this "cleaned" bitmap B4i function bitmap.Rotate works as expected.
I attached a test. Pls, let me know, if you will notice any problem.


Semen Matusovskiy

Well-Known Member
Licensed User
Not so simple :) Check width and height of "rotated" bitmap.
If to take a file "90 degrees.jpg", B4I will show Width = 768 Height = 1024 instead of Width = 1024 Height = 768.

What I need to do ... In my sample there are four pictures.
If to open JPG files in Microsoft Office, all pictures have the same correct orientation. But if to open JPG in stupid Microsoft Paint or IrfanView, the orientation will be correct for "0 degrees.jpg" only.
Our webserver works exactly like Microsoft Paint (ignores orientation flag in EXIF DATA). That's why my program must convert files "90 degrees", "180degrees", "270 degrees" to "0 degrees".