开发者

working with camera in android

开发者 https://www.devze.com 2023-03-25 18:28 出处:网络
I\'m working on an application in android which uses the camera and I\'m facing the following issue. 1.If I simply take a picture with no special settings for the camera(orientation settings I mean)

I'm working on an application in android which uses the camera and I'm facing the following issue.

1.If I simply take a picture with no special settings for the camera(orientation settings I mean) also the preview and my resulting picture will look like this: http://i51.tinypic.com/xfx3jq.png which is not right at all. Now what I do with this picture is to upload it to a website where is set up with the same orientation!!!

2.If I setup my activity in the LANDSCAPE mode then my picture will look like this: http://i56.tinypic.com/152c41e.png with the buttons setup the way you seee.And any extra view is setup wrong like in here: http://i56.tinypic.com/16ifxqx.png which is extremly wrong. And above all when I upload the picture to a website is not orientated corectly anymore and it looks like this: http://i51.tinypic.com/xfx3jq.png.

How should I proceed in order to get a corectly orientated picture with the extra view looking normally and when I upload it to the website to look also vertically orientated??? Thank you!

I must say that I'm bulilding my own camera in android.

EDIT: I tried

Camera.Parameters p = mCamera.getParameters();
p.setRotation(270);
开发者_如何学编程mCamera.setParameters(p);

but has no effect upon my image!

EDIT:

in my onCreate() I've setup my orientation this way:

this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

this makes my image look the way I want to look, but my views are setup astray and when I load the image to a website it comes back to the initial orientation!


Older Android-Versions had a bug concerning the camera orientation, adding this to your onCreate()-Method should fix this (for backward compatibility this is also the case in newer android versions):

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

This is regardless of the orientation you want. But beware: this will help on a lot of phones, but e.g. will terribly fail on samsung phones as they seem to have fixed this issue breaking backward compatibility. For those you can add something like this (but only for those devices):

Camera.Parameters parameters = camera.getParameters();
parameters.set("orientation", "portrait");
parameters.set("rotation", "90");

Have a look here for further informations: Orientation Problem in Camera

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号