"拍摄照片​​和present它"在三星Galaxy S肖像模式 [英] "take a picture and present it" in portrait mode on Samsung Galaxy S

查看:173
本文介绍了"拍摄照片​​和present它"在三星Galaxy S肖像模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想简单地拍照和present它与我的三星Galaxy S的ImageView的。它的工作很好,当我这样做是对景观,但不可以上的肖像。我没有得到任何错误或异常 - 只是没有得到任何东西......有很多关于这个主题的问题,这似乎是有问题的(一些有关相机方向),但counldn't想出了一个简单的最终解决方案拍摄照片和present为code。 这是我的(问题)code不工作:

I am trying to simply take a picture and present it in an ImageView with my samsung galaxy s. it's working fine when I do it on landscape but not on portrait. I am not getting any error or exception - just not getting anything... There is a lot of questions about this topic and it seems to be problematic (something about camera orientation) but counldn't figure out the final solution for a simple "take a picture and present it" code. here is my (problematic) code that doesn't work:

private void setUpListeners() {
    takePicture.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            Intent cameraIntent = new Intent(
                    android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
        }
    });
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        if (requestCode == CAMERA_PIC_REQUEST) {
            Log.d("onActivityResult", "CAMERA_PIC_REQUEST returned");
            dishImage = (Bitmap) data.getExtras().get("data");
            if (dishImage==null)
                Log.d("onActivityResult", "dishImage==null");
            imageView = (ImageView) findViewById(R.id.dishinfodishimageview);
            imageView.setImageBitmap(dishImage);
            imageView.setVisibility(View.VISIBLE);
            takePicture.setVisibility(View.GONE);
            (new UploadImage()).execute(null);
        }
    } else {
        Log.e("onActivityResult",
                "no able to presenting the picture of the dish");
    }

}

我只是需要一个code,工程(在任何设备上)或修正我的code ... 谢谢。

I just need a code that works (on any device) or a fix to my code... thx.

推荐答案

而之所以的onCreate()被称为是因为当你做人像时调用摄像头活动方向,它会改变方向,并摧毁你的previous活动。完成后的 onActivityResult(),你的活动将被重新创建。

The reason that onCreate() is called is because when you do call the camera activity during the portrait orientation, it will change the orientation and destroy your previous activity. After finishing the onActivityResult(), your activity will be re-created.

一个解决这个问题的方法是设置明显忽略的方向变化而变化,则可以使用该做的:

One solution to this problem is to set the manifest to ignore changes on orientation change, you can do it by using this:

<activity android:name=".MyMainActivity"
     android:configChanges="orientation"
     android:label="@string/app_name" />

如果您使用的是API 13级开始,你可以考虑屏幕尺寸的configChanges清单。

If you are using API starts with level 13, you can consider screenSize for the configChanges manifest.

这篇关于&QUOT;拍摄照片​​和present它&QUOT;在三星Galaxy S肖像模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆