android - setRotation(90) to take picture in portrait mode does not work on samsung devices -
according documentation, setrotation(90) should rotate captured jpeg picture (takepicture in landscape mode.
this works fine on htc phone, not work on samsung google nexus s , samsung galaxy s3. bug?
i know can use matrix transform rotation, wish os can more efficiently, , don't want risk over-rotating on other devices.
edit
setting camera.setdisplayorientation(90);
made preview in portrait mode, did not have affect on picture taken.
further, besides setrotation
, have tried set picture size - flip h
w
: parameters.setpicturesize(1200, 1600);
. did not have affect.
solution
apparently samsung phones set exif orientation tag, rather rotating individual pixels. ariefbayu
suggested, reading bitmap using bitmapfactory
not support tag. code sample solution, , solution compatible using insamplesize
.
i try answer in relation exif tag. did:
bitmap realimage = bitmapfactory.decodestream(stream); exifinterface exif=new exifinterface(getrealpathfromuri(imagepath)); log.d("exif value", exif.getattribute(exifinterface.tag_orientation)); if(exif.getattribute(exifinterface.tag_orientation).equalsignorecase("6")){ realimage=imageutil.rotate(realimage, 90); }else if(exif.getattribute(exifinterface.tag_orientation).equalsignorecase("8")){ realimage=imageutil.rotate(realimage, 270); }else if(exif.getattribute(exifinterface.tag_orientation).equalsignorecase("3")){ realimage=imageutil.rotate(realimage, 180); }
the imageutil.rotate()
:
public static bitmap rotate(bitmap bitmap, int degree) { int w = bitmap.getwidth(); int h = bitmap.getheight(); matrix mtx = new matrix(); mtx.postrotate(degree); return bitmap.createbitmap(bitmap, 0, 0, w, h, mtx, true); }
Comments
Post a Comment