简体   繁体   English

在Android相机拍摄的imageview照片中显示图片

[英]display picture in imageview photo taken by camera in android

I have a problem in Android development with camera. 我在使用相机进行Android开发时遇到问题。 i try to take a pic and display it in to imageview but the result does not show but it works fine for Galaxy Note but i doesnt work for Galaxy S3 我尝试拍摄一张照片并将其显示在imageview中,但结果没有显示,但对于Galaxy Note来说效果很好,但对于Galaxy S3不起作用

My Code is Bellow 我的代码是贝娄

Camera Activity 相机活动

package com.nfs;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class Camera extends Activity {
    private static final int CAMERA_REQUEST = 500;
    private ImageView imageView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camera);

    this.imageView = (ImageView) findViewById(R.id.imgLoad);
    Button bt = (Button) findViewById(R.id.btCam);

    bt.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
                    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
                    startActivityForResult(intent, CAMERA_REQUEST);                         

        }
    });
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
        Bitmap photo = (Bitmap) data.getExtras().get("data");
        imageView.setImageBitmap(photo);
    }
}

} }

layout 布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/btCam"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Click Here" />

    <ImageView
        android:id="@+id/imgLoad"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.70"
        android:src="@drawable/icon" />
</LinearLayout>

Try This: 尝试这个:

@Override
protected void onActivityResult(int requestCode, int resultCode,
        final Intent imageReturnedIntent) {
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent);

    switch (requestCode) {
    case 1:
        if (resultCode == RESULT_OK) {
            try {
                try {
                    Uri selectedImage = imageReturnedIntent.getData();
                    bmpSelectedImage = getThumbnail(selectedImage);

                    set_img_camera.setImageBitmap(bmpSelectedImage);

                } catch (IOException e) {
                    e.printStackTrace();
                }

            } catch (Exception e) {
                Log.d("image error", e.toString());
            }
        }
    }
}

嗨,尝试一下我的代码,它工作正常。我想这可以解决您的问题。链接如下:-Imp Link

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Android中的相机拍摄的imageview照片中显示图片 - How to display picture in imageview photo taken by camera in android ImageView不显示从手机摄像头或照片库拍摄的图像 - ImageView does not display image taken from phone camera or photo gallery Android相机:拍照后获取照片Uri - Android Camera: Get Picture Uri after the photo is taken 从ImageView中显示的相机拍摄的照片始终是水平的Android - Picture taken from camera displayed in ImageView is always horizontal Android 设置使用照相机拍的照片作为在imageview的thumbnai - Setting photo taken using camera as thumbnai in an imageview 在Android中旋转相机拍摄的照片 - Rotating picture taken by Camera in Android Android:如何通过自定义相机拍摄的照片设置imageview - Android: How do i set imageview with photo taken through a custom camera Android如何在拍摄自定义相机时根据方向旋转照片 - Android how to rotate a photo depending on orientation when picture is taken custom camera Android Camera图片未显示在ImageView中 - Android Camera picture not showing in ImageView 在imageview中使用时从相机或图库拍摄的照片,其方向发生变化,有时在Android中垂直拉伸 - Picture taken from camera or gallery when using in imageview its orientation getting changed, and sometimes vertically stretched in Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM