2016-03-30 43 views
1

imは1枚の画像をキャプチャして表示する簡単なアンドロイドカメラアプリケーションです。キャプチャ部分は、しかし、私はimageview.thereに表示カント働いているすべてのエラーを波平が、logcatの一つにキャプチャ画像は画像ビューに表示されません

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.lala.camera.MainActivity" 
    android:orientation="vertical"> 

    <Button 
     android:layout_width="200dp" 
     android:layout_height="wrap_content" 
     android:text="Capture Image" 
     android:id="@+id/button" 
     android:layout_gravity="center_horizontal" 
     /> 

    <ImageView 
     android:layout_width="350dp" 
     android:layout_height="300dp" 
     android:id="@+id/image_view" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginTop="20dp" 
     /> 

</LinearLayout> 
activity_main.xmlこの

Bitmap too large to be uploaded into a texture (3120x4208, max=4096x4096) 

MainActivity.java

import android.app.Activity; 
import android.content.Intent; 
import android.graphics.drawable.Drawable; 
import android.net.Uri; 
import android.os.Bundle; 
import android.provider.MediaStore; 
import android.view.View; 
import android.widget.Button; 
import android.widget.ImageView; 

import java.io.File; 

public class MainActivity extends Activity { 

    Button button; 
    ImageView imageView; 
    static final int CAM_REQUEST = 1; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     button = (Button) findViewById(R.id.button); 
     imageView = (ImageView) findViewById(R.id.image_view); 
     button.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent camera_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
       File file = getfile(); 
       camera_intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); 
       startActivityForResult(camera_intent,CAM_REQUEST); 

      } 
     }); 
    } 

    private File getfile(){ 

     File folder = new File("sdcard/camera_app"); 

     if(!folder.exists()){ 
      folder.mkdir(); 
     } 

     File image_file = new File (folder, "cam_image.jpg"); 
     return image_file; 
    } 

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     String path = "sdcard/camera_app/cam_image.jpg"; 
     imageView.setImageDrawable(Drawable.createFromPath(path)); 

    } 
} 

を述べました

AndroidManifest.xml

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

    <uses-feature android:name="android.hardware.camera2"/> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
     <activity android:name=".MainActivity"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

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

</manifest> 

答えて

0

画像が大きすぎますので、画像のサイズを変更する必要があります。 試してみてください:

imageView.setImageDrawable(resize(Drawable.createFromPath(path))); 

private Drawable resize(Drawable image) { 
    Bitmap bitmap = ((BitmapDrawable)image).getBitmap(); 
    Bitmap bitmapResized = Bitmap.createScaledBitmap(bitmap , WIDTH, HEIGHT, false); 
    return new BitmapDrawable(getResources(), bitmapResized); 
} 
+0

ありがとう、それは素晴らしい作品です。私はイメージのサイズを変更しなければならないことを知りませんでした – user3662097

関連する問題