捕获的图像没有设置为imageview没有在samsung s3 Duos上工作

时间:2015-06-25 10:48:12

标签: android

我做了一个简单的应用程序来在imageview中设置图像。

图像由相机拍摄。

我的代码在除三星s3 Duos android版本4.4.4之外的所有设备中都能正常工作

我的代码

package com.example.imageviewdemo;

import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.view.Display;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.ImageView;

public class MainActivity extends Activity {

    ImageView myimage;
    final int CAMERA_CAPTURE_PHOTO = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        myimage=(ImageView)findViewById(R.id.imageView1);
        myimage.setOnClickListener(upload);
    }

    private OnClickListener upload=new OnClickListener()
    {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(captureIntent, CAMERA_CAPTURE_PHOTO);

        }

    };

    public void onActivityResult(int requestCode,int resultCode,Intent data)
    {
        if(resultCode==RESULT_OK)
        {

            if(requestCode==CAMERA_CAPTURE_PHOTO)
            {

                Bundle extras = data.getExtras();
                Bitmap photoImage = extras.getParcelable("data");
                myimage.setImageBitmap(photoImage);
            }   
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

AndroidManifest文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.imageviewdemo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.imageviewdemo.MainActivity"
            android:label="@string/app_name"
            android:configChanges="orientation|keyboardHidden"
        android:screenOrientation="portrait"> >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

我的logcat显示信息

06-25 16:27:04.635: I/Timeline(16939): Timeline: Activity_idle id: android.os.BinderProxy@4233b388 time:36037001
06-25 16:27:06.595: W/IInputConnectionWrapper(16939): showStatusIcon on inactive InputConnection
06-25 16:27:06.705: E/OpenGLRenderer(16939): SFEffectCache:clear(), mSize = 0
06-25 16:27:15.125: W/ApplicationPackageManager(16939): getCSCPackageItemText()
06-25 16:27:15.245: I/Timeline(16939): Timeline: Activity_idle id: android.os.BinderProxy@4233b388 time:36047610
06-25 16:27:15.655: W/ApplicationPackageManager(16939): getCSCPackageItemText()
06-25 16:27:15.765: E/ViewRootImpl(16939): sendUserActionEvent() mView == null
06-25 16:27:15.795: I/Timeline(16939): Timeline: Activity_idle id: android.os.BinderProxy@4233b388 time:36048161

请任何人帮忙解决这个问题...

1 个答案:

答案 0 :(得分:0)

最后我找到了解决方案

使用重新创建活动概念我保存了我的活动状态并将其恢复,然后将捕获的图像设置为图像视图。

代码

 static final String STATE_image = "image";
@Override
    public void onSaveInstanceState(Bundle savedInstanceState) {
        // Save the user's current  state
        savedInstanceState.putParcelable(STATE_image, photoImage);
        // Always call the superclass so it can save the view hierarchy state
        super.onSaveInstanceState(savedInstanceState);
    }

    public void onRestoreInstanceState(Bundle savedInstanceState) {
        // Always call the superclass so it can restore the view hierarchy
        super.onRestoreInstanceState(savedInstanceState);

        // Restore state members from saved instance
        photoImage=savedInstanceState.getParcelable(STATE_image);
        myimage.setImageBitmap(photoImage);  
    }