Android Get Orientation of a Camera Bitmap? and Rotate Back -90 Degrees

Android image resizing and preserving EXIF data (orientation, rotation, etc.)

As others have indicated, you must copy the Exif data from the original image to the final resized image. The Sanselan Android library is typically best for this. Depending on Android OS version, the ExifInterface sometimes corrupts the Exifdata.

In addition, the ExifInterface also handles a limited number of Exif tags -- namely only the tags that it "knows" about. Sanselan on the other hand will keep all Exiftags and marker notes.

Here is a blog post that shows how to use Sanselan for copying image data:

Copying Exif metadata using Sanselan

BTW, on Android I also tend to rotate the images and remove the Orientation Exiftag. For example, on a Nexus S with Android 4.03, the camera was setting an orientation tag in the Exifmetadata, but the webview was ignoring that information and displaying the image incorrectly. Sadly, rotating the actual image data and removing the Exiforientation tag is the only way to get every program to display images correctly.

How to detect face orientation changes on live preview ,face detection android

I have solved this issue by taking Euler Z value of detected face.I am posting my code:

I have rotated the rectangle and the mask bitmap on detected face when orientation changes;

RectF dest = new RectF((int) left, (int) top, (int) right, (int) bottom);

Matrix m = new Matrix();

m.setRotate(face.getEulerZ(),dest.centerX(),dest.centerY());
m.mapRect(dest);

Rotated bitmap.

public Bitmap rotate_bitmap(Bitmap bmp,float degree){
Matrix matrix = new Matrix();

matrix.postRotate(degree);

return Bitmap.createBitmap(bmp , 0, 0, bmp .getWidth(), bmp .getHeight(), matrix, true);
}

Drawing rotated mask on canvas.

            canvas.drawBitmap(rotate_bitmap(faceTrackerActivity.getBitmapItem("face"),face.getEulerZ()), null, dest, null);

Also, set FAST MODE to face detector.

FaceDetector detector = new FaceDetector.Builder(context)
.setClassificationType(FaceDetector.ALL_CLASSIFICATIONS)

.setMode(FaceDetector.FAST_MODE)
.build();`

Rotating an image around a specified point doesn't work! (Android)

I am using a custom ImageView where I set the angle rotation.

public class CompassImage extends ImageView {
private float angleRotation;

public CompassImage(Context context) {
super(context);
}

public CompassImage(Context context, AttributeSet attrs) {
super(context, attrs);
}

public CompassImage(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

public void setAngleRotation(float angleRotation) {
this.angleRotation = angleRotation;
invalidate();
}

@Override
protected void onDraw(Canvas canvas) {
Rect clipBounds = canvas.getClipBounds();
canvas.save();
canvas.rotate(angleRotation, clipBounds.exactCenterX(), clipBounds.exactCenterY());
super.onDraw(canvas);
canvas.restore();
}
}

If you play around with clipBounds you may find that helpful.

Android Maps v2 rotate mapView with compass

OK, i figured it out myself. first you need to calculate the bearing from the compass.
then the Maps api-2 camera can be rotated.

public void updateCamera(float bearing) {
CameraPosition currentPlace = new CameraPosition.Builder()
.target(new LatLng(centerLatitude, centerLongitude))
.bearing(bearing).tilt(65.5f).zoom(18f).build();
googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(currentPlace));

}

set SensorListener in your code and call this method in onSensorChanged event. i have added a tilt value so the map will rotate in 3D.

How do I know if an image is rotated on the buffer?

Well, as it turn out the only necessary information is the Exif metadata. rotationDegrees contains the final orientation the image should be in, starting from the base orientation, but the Exif metadata only shows the rotation I had to make to get the final result. So rotating according to TAG_ORIENTATION solved the issue.

  • UPDATE: This was an issue with the CameraX library itself. It was fixed in 1.0.0-beta02, so now the exif metadata and rotationDegrees contain the same information.


Related Topics



Leave a reply



Submit