2013-05-21 2 views
1

imagelook에서 만든 png 파일을 표시하려고합니다. 프로그램을 시작하고 showCreatedPng 버튼을 클릭하면 에뮬레이터 화면에 흰색 빈 페이지가 나타납니다.안드로이드가 내부/외부 저장소에서 이미지를 가져옵니다.

LogCat 메시지 : (에뮬레이터로 인해 Logcat에 오류가 표시 될 수 있습니다. 내 에뮬레이터에 200MB의 SD 카드가 있지만 컴퓨터에서 생성 된 PNG가 어디에 있는지 찾을 수 없습니다. 내 전화 프로그램을 시작하면 PNG가 저장됩니다. GT-I9100 \ 전화 폴더에. 나는 폴더 내부 폴더 것 같다. 어쨌든, 내가 만든 PNG로 파일을. 도와주세요 볼 수 없습니다.)

05-21 21:53:39.764: E/BitmapFactory(1335): Unable to decode stream: java.io.FileNotFoundException: /mnt/sdcard/*.png: open failed: ENOENT (No such file or directory) 

이 내가 사용하는 코드입니다. 저장을위한

:

private void saveImageToExternalStorage(Bitmap bitmap) { 
    String qrPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/"; 
    try 
    { 
     File dir = new File(qrPath); 
     if (!dir.exists()) { 
      dir.mkdirs(); 
     } 
     OutputStream fOut = null; 
     File file = new File(qrPath, "QRCode.png"); 
     if(file.exists()){ 
      file.delete(); 
      file.createNewFile(); 
      fOut = new FileOutputStream(file); 
      bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut); 
      fOut.flush(); 
      fOut.close(); 
     } 
    } 
    catch (Exception e) { 
     Log.e("saveToExternalStorage()", e.getMessage()); 
    } 
} 

그리고 코드에 대한 PNG로 파일을 얻을 : 당신의 도움에 대한

String qrPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/*.png"; 
BitmapFactory.Options options = new BitmapFactory.Options(); 
options.inPreferredConfig = Bitmap.Config.ARGB_8888; 
Bitmap mustOpen = BitmapFactory.decodeFile(qrPath, options); 

setContentView(R.layout.qr_image); 
ImageView imageView = (ImageView) findViewById(R.id.qr_image); 
imageView.setImageBitmap(mustOpen); 

감사합니다.

답변

1

*.png이라는 파일을 열려고합니다. 이것은 아마도 이렇게 코드

Environment.getExternalStorageDirectory().getAbsolutePath() + "/QRCode.png"; 
+0

Thaks a lot : D 가끔은 이런 작은 것들을 볼 수 없습니다. :디 –

-1
 Use the adb tool with push option to copy test2.png onto the sdcard. 

    bash-3.1$ /usr/local/android-sdk-linux/tools/adb push test2.png /sdcard/ 


    This is the easiest way to load bitmaps from the sdcard. Simply pass the path to the image to BitmapFactory.decodeFile() and let the Android SDK do the rest. 

    package higherpass.TestImages; 

    import android.app.Activity; 
    import android.graphics.Bitmap; 
    import android.graphics.BitmapFactory; 
    import android.os.Bundle; 
    import android.widget.ImageView; 

    public class TestImages extends Activity { 
     /** Called when the activity is first created. */ 
     @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.main); 
      ImageView image = (ImageView) findViewById(R.id.test_image); 
      Bitmap bMap = BitmapFactory.decodeFile("/sdcard/test2.png"); 
      image.setImageBitmap(bMap); 
     } 
    } 

All this code does is load the image test2.png that we previously copied to the 
sdcard. The BitmapFactory creates a bitmap object with this image 

, QRCode.png해야하며 우리는 이미지 뷰 구성 요소를 업데이트 할 ImageView.setImageBitmap() 메서드를 사용합니다.

관련 문제