有意图的相机图像捕获错误

时间:2014-10-13 08:11:58

标签: android camera

已编辑:我在使用意图进行Android相机图像捕获时遇到错误。我实际上是想通过相机拍摄照片并在ImageView上显示捕获的图像。以下是我得到的错误。

Bitmap cannot be resolved to a type
mImageView cannot be resolved

有谁可以请帮助我。我在下面制作了我的代码。

package com.example.imageupload;

import android.support.v7.app.ActionBarActivity;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends ActionBarActivity {
    TextView messageText;
    Button uploadButton;
    int serverResponseCode = 0;
    ProgressDialog dialog = null;

    String upLoadServerUri = null;

    /**********  File Path *************/
    final String uploadFilePath = "/mnt/sdcard/";
    final String uploadFileName = "";

    static final int REQUEST_IMAGE_CAPTURE = 1;
    private void dispatchTakePictureIntent() {
        Intent takePictureIntent = new Intent (MediaStore.ACTION_IMAGE_CAPTURE);
        if (takePictureIntent.resolveActivity(getPackageManager())!=null) {
            startActivityForResult(takePictureIntent,REQUEST_IMAGE_CAPTURE);
        }

        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            if(requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK){
                Bundle extras =data.getExtras();
                Bitmap imageBitmap = (Bitmap) extras.get("data");
                mImageView.setImageBitmap(imageBitmap);
            }
        }

    }

1 个答案:

答案 0 :(得分:-1)

感谢各位关于开发相机应用编码的疑问。而且我已成功完成编码。这是我做过的错误编码。 (对不起,我是新人。如果代码太模糊或者别的话,很抱歉......)

//MainActivity.java//
package com.example.imageupload;

import android.support.v7.app.ActionBarActivity;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends ActionBarActivity {
	TextView messageText;
    Button uploadButton;
    int serverResponseCode = 0;
    ProgressDialog dialog = null;
        
    String upLoadServerUri = null;
     
    /**********  File Path *************/
    final String uploadFilePath = "/mnt/sdcard/";
    final String uploadFileName = "";
    
    static final int REQUEST_IMAGE_CAPTURE = 1;
    private void dispatchTakePictureIntent() {
    	Intent takePictureIntent = new Intent (MediaStore.ACTION_IMAGE_CAPTURE);
    	if (takePictureIntent.resolveActivity(getPackageManager())!=null) {
    		startActivityForResult(takePictureIntent,REQUEST_IMAGE_CAPTURE);
    	}
    	
    		}
    
    @Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if(requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK){
			Bundle extras =data.getExtras();
			Bitmap imageBitmap = (Bitmap) extras.get("data");
			ImageView mImageView = new ImageView(this);
			mImageView.setImageBitmap(imageBitmap);
			
    	}
    	
    }