2011-04-23 3 views
1

카메라를 시작하고 사진을 찍는 응용 프로그램에서 작동 중이며 카메라 작동을 사용하지 않았지만 카메라 응용 프로그램을 작성했고 촬영 한 이미지를 "temPic"이라는 폴더의 내부 전화 저장안드로이드에 내부 저장 장치에 이미지를 저장합니다.

다음 코드는 폴더와 이미지를 생성하지만 tempPic 이미지를 발견했을 때 image1.jpg라는 이미지를 발견했으며 크기는 461115입니다. 이미지를 저장하려고했습니다. SDcard 디렉토리와 같은 크기입니다.)하지만 SDcard에서 흑백 이미지를 두 번 클릭하면 흑백 이미지가 나타납니다.

FileManipulator fileFormat = new FileManipulator(
       getApplicationContext()); 
     String path = fileFormat.createFolder_PStrg("tempPic") + "/image1.jpg";  
     File file = new File(path); 
     Uri outputFileUri = Uri.fromFile(file); 

     OutputStream imageFileOS; 
     try { 


      imageFileOS = getContentResolver().openOutputStream(outputFileUri); 
      imageFileOS.write(arg0); 
      imageFileOS.flush(); 
      imageFileOS.close(); 
      Toast.makeText(AndroidCamera.this, 
        file.length()+"", 
        Toast.LENGTH_LONG).show(); 
      Toast.makeText(AndroidCamera.this, 
        "Image saved: " + outputFileUri.toString(), 
        Toast.LENGTH_LONG).show(); 

     } catch (FileNotFoundException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     camera.startPreview(); 
+0

화일 형식을 시험은 잘 작동합니다 개인 권한이있는 폴더로 이동 다른 내부 저장 폴더에 이미지를 이동하지만, 개인의 허가를

 //the temp folder to start the camera activity with String path = getDir("images", Context.MODE_WORLD_WRITEABLE).getPath() + "/test.jpg"; //start the camera activity File file = new File(path); Uri outputFileUri = Uri.fromFile(file); Intent intent = new Intent( android.provider.MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); startActivityForResult(intent, CAMERA_ACTIVITY); 

에 따라 같이하여 onActivityResult 방법으로 할 수 있습니다 돌아갑니다. createFol der_PStrg는 내부 저장소에 폴더를 만드는 방법입니다. – alex

답변

8

이 방법이 도움이 될지 모르지만이 방법으로 파일을 SD 카드에 저장하면 작동합니다. 카메라 활동을 사용하여 다른 응용 프로그램이이 폴더에 작성하고 이후에 다음의 경로로 이미지를 가지고 할 수 있도록 쓰기 권한이 임시 폴더를 생성하여 내부 스토리지에 이미지를 저장하지 않는 이유는

 public void saveToSD(Bitmap outputImage){ 


      File storagePath = new File(Environment.getExternalStorageDirectory() + "/MyPhotos/"); 
      storagePath.mkdirs(); 

      File myImage = new File(storagePath, Long.toString(System.currentTimeMillis()) + ".jpg"); 

      try { 
       FileOutputStream out = new FileOutputStream(myImage); 
       outputImage.compress(Bitmap.CompressFormat.JPEG, 80, out); 
       out.flush();  
       out.close(); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      }    
     } 
+0

내부 저장소에서 작동합니까? – Behzad

+1

이 경우 내부는 장치에 내장 된 SD 카드를 의미하지만 다른 방식으로 액세스되는 응용 프로그램 개인 저장소는 아닙니다. – Lumis

0

카메라 활동은 당신은 내가 그것을

+0

이것은 실제 기기에서 작동하지 않습니다. –

관련 문제