2016-04-18 20 views
0

携帯電話のカメラを使用して写真を撮ってImageViewで表示するアプリケーションを作ったが、それは表示されません。AndroidスタジオアプリケーションImageViewで写真を撮るときに画像が表示されない

ここに私のJavaコードです。ここで

package com.example.gonalo.photoactivitie; 

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"); 

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

    File image_file = new File(folder, "cam_image.lpg"); 

    return image_file; 
} 

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

は、ここに私jar.xmlファイルのコード

<Button 
    android:layout_width="200dp" 
    android:layout_height="wrap_content" 
    android:text="Capture Image" 
    android:id="@+id/button" 
    android:layout_gravity="center_horizontal" 
    android:layout_below="@+id/image_view" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="40dp" /> 
<ImageView 
    android:layout_width="350dp" 
    android:layout_height="300dp" 
    android:id="@+id/image_view" 
    android:layout_gravity="center_horizontal" 
    android:layout_marginTop="20dp"/> 

である私が作成するJavaで言うので、私のmanifest.fileコードが

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

あるので、私はその考えます私は写真を撮る新しいパス、それはそれをやっていない、私のlogcatのためにこれを言っている。

04-18 22:54:03.940 1508-1508/? E/Zygote: MountEmulatedStorage() 
04-18 22:54:03.940 1508-1508/? E/Zygote: v2 
04-18 22:54:03.940 1508-1508/? I/libpersona: KNOX_SDCARD checking this for 10259 
04-18 22:54:03.940 1508-1508/? I/libpersona: KNOX_SDCARD not a persona 
04-18 22:54:03.940 1508-1508/? I/SELinux: Function: selinux_compare_spd_ram , priority [2] , priority version is VE=SEPF_SM-A500FU_5.0.2-1_0039 
04-18 22:54:03.950 1508-1508/? E/SELinux: [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL 
04-18 22:54:03.950 1508-1508/? I/art: Late-enabling -Xcheck:jni 
04-18 22:54:03.990 1508-1508/? D/TimaKeyStoreProvider: TimaSignature is unavailable 
04-18 22:54:03.990 1508-1508/? D/ActivityThread: Added TimaKeyStore provider 
04-18 22:54:04.130 1508-1508/com.example.gonalo.photoactivitie D/PhoneWindow: *FMB* installDecor mIsFloating : false 
04-18 22:54:04.130 1508-1508/com.example.gonalo.photoactivitie D/PhoneWindow: *FMB* installDecor flags : -2139029248 
04-18 22:54:04.550 1508-1589/com.example.gonalo.photoactivitie D/OpenGLRenderer: Render dirty regions requested: true 
04-18 22:54:04.570 1508-1508/com.example.gonalo.photoactivitie D/PhoneWindow: *FMB* isFloatingMenuEnabled mFloatingMenuBtn : null 
04-18 22:54:04.570 1508-1508/com.example.gonalo.photoactivitie D/PhoneWindow: *FMB* isFloatingMenuEnabled return false 
04-18 22:54:04.680 1508-1508/com.example.gonalo.photoactivitie D/SRIB_DCS: log_dcs ThreadedRenderer::initialize entered! 
04-18 22:54:04.690 1508-1589/com.example.gonalo.photoactivitie I/Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build: SKARAJGA_AU_LINUX_ANDROID_LA.BR.1.1.2_RB1.05.00.02.031.018+PATCH[ES]_msm8916_32_refs/tags/AU_LINUX_ANDROID_LA.BR.1.1.2_RB1.05.00.02.031.018__release_ENGG (I856e09677e) 
                      OpenGL ES Shader Compiler Version: E031.25.03.02 
                      Build Date: 04/06/15 Mon 
                     Local Branch: 
                     Remote Branch: refs/tags/AU_LINUX_ANDROID_LA.BR.1.1.2_RB1.05.00.02.031.018 
                     Local Patches: 112c106f3772623daa7b4181c6cf23491044ead1 Revert "Disable ASTC on A405" 
                          58a118cb818fdc906095a49a90977c15f9d3b223 Remove ASTC 
04-18 22:54:04.700 1508-1589/com.example.gonalo.photoactivitie I/OpenGLRenderer: Initialized EGL, version 1.4 
04-18 22:54:04.730 1508-1589/com.example.gonalo.photoactivitie D/OpenGLRenderer: Get maximum texture size. GL_MAX_TEXTURE_SIZE is 4096 
04-18 22:54:04.730 1508-1589/com.example.gonalo.photoactivitie D/OpenGLRenderer: Enabling debug mode 0 
04-18 22:54:04.810 1508-1508/com.example.gonalo.photoactivitie I/Timeline: Timeline: Activity_idle id: [email protected] time:444778388 
04-18 22:54:06.010 1508-1508/com.example.gonalo.photoactivitie D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN 
04-18 22:54:06.230 1508-1508/com.example.gonalo.photoactivitie V/ActivityThread: updateVisibility : ActivityRecord{33fd7c3a [email protected] {com.example.gonalo.photoactivitie/com.example.gonalo.photoactivitie.MainActivity}} show : false 
04-18 22:54:06.260 1508-1589/com.example.gonalo.photoactivitie D/OpenGLRenderer: endAllStagingAnimators on 0xb805b7a8 (RippleDrawable) with handle 0xb8062168 
04-18 22:54:13.870 1508-1508/com.example.gonalo.photoactivitie E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: SdCard/Camera/cam_image.jpg: open failed: ENOENT (No such file or directory) 
04-18 22:54:13.970 1508-1508/com.example.gonalo.photoactivitie D/SRIB_DCS: log_dcs ThreadedRenderer::initialize entered! 
04-18 22:54:14.020 1508-1508/com.example.gonalo.photoactivitie I/Timeline:  Timeline: Activity_idle id: [email protected] time:444787597 

すべてのヘルプを返信しますか?

答えて

1

ドロアブルを作成するための正しいパスが指定されていません。あなたが作成するファイルの正しいパスを提供していないので、あなたのgetFile()を変更、また

imageView.setImageDrawable(Drawable.createFromPath(getFile().getAbsolutePath())); 

- - このような正しいパスを使用して、私は以前、何かを逃した

private File getFile() { 


     File folder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "My_folder"); 

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

     File image_file = new File(folder, "cam_image.lpg"); 

     return image_file; 
    } 
+0

申し訳ありません。編集された回答をお試しください。 –

+0

正しいパスが指定されていないため、ファイルが作成されていないためです。どこにファイルを作成しようとしていますか?デバイスのカメラフォルダですか? –

+0

これで、更新された回答を試すことができます。 –

関連する問題