2016-08-30 7 views
-3

미리 감사드립니다.안드로이드에서 이미지 파일을 저장하지 않고 이미지를 얻는 방법

나는 다음 contidion에서 코딩 중이다. 내 응용 프로그램에서

a. use internal camera app(I use Intent and other app to take pickture).
b. get image without saving into file. 는, 사용자가 신용 카드의 pickture을 서버로 보낼 수 있습니다. 신용 카드 이미지 파일은 필요 없으며 이미지를 파일로 저장하는 것은 보안에 좋지 않습니다.

가능합니까?

불가능할 경우 다른 것이 있습니까?

a. jpg 파일 열기, 모든 픽셀을 검정색으로 편집
b. 사용 https://github.com/Morxander/ZeroFill

위짓 (Whitch) 방법이 적절합니까?

+0

임시 파일에 저장 한 다음 서버로 전송을 마치면 삭제할 수 있습니다. –

+0

@SohailZahid 도와 주셔서 감사합니다 !! 어떻게 임시 파일에 저장할 수 있습니까? –

+0

@Sohail Zahid, 도와 주셔서 감사합니다 !! 어떻게 임시 파일에 저장할 수 있습니까? –

답변

1

짧은 대답은 NO입니다.
기본 카메라 앱에서 이미지를 저장하지 않고 사진을 가져올 수는 없습니다.
카메라 API를 사용하여 타사 기본 시스템 사진 앱을 사용하지 않고 앱 내부에서 사진을 찍을 수 있습니다.

가 가
+0

감사합니다. 카메라 API를 사용하거나 이미지 파일을 지워야한다는 것을 알고 있습니다. –

1

전체 Source.

요청을 여기에 AndroidManifest.xml에이 권한 봐 :

static final int REQUEST_IMAGE_CAPTURE = 1; 
private Bitmap mImageBitmap; 
private String mCurrentPhotoPath; 
private ImageView mImageView; 

는 그런 다음 onClickIntent 화재 : 당신의 Activity

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

을,이 정의에 의해 시작 :

Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
if (cameraIntent.resolveActivity(getPackageManager()) != null) { 
    // Create the File where the photo should go 
    File photoFile = null; 
    try { 
     photoFile = createImageFile(); 
    } catch (IOException ex) { 
     // Error occurred while creating the File 
     Log.i(TAG, "IOException"); 
    } 
    // Continue only if the File was successfully created 
    if (photoFile != null) { 
     cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); 
     startActivityForResult(cameraIntent, REQUEST_IMAGE_CAPTURE); 
    } 
} 

는 다음과 같은 지원 방법을 추가

private File createImageFile() throws IOException { 
    // Create an image file name 
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); 
    String imageFileName = "JPEG_" + timeStamp + "_"; 
    File storageDir = Environment.getExternalStoragePublicDirectory(
      Environment.DIRECTORY_PICTURES); 
    File image = File.createTempFile(
      imageFileName, // prefix 
      ".jpg",   // suffix 
      storageDir  // directory 
    ); 

    // Save a file: path for use with ACTION_VIEW intents 
    mCurrentPhotoPath = "file:" + image.getAbsolutePath(); 
    return image; 
} 

가 그런 결과가 나타납니다

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) { 
     try { 
      mImageBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.parse(mCurrentPhotoPath)); 
      mImageView.setImageBitmap(mImageBitmap); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 
} 

이 작품은 developer.android.com의 코드와는 다른 MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.parse(mCurrentPhotoPath))입니다 만들 었는지. 원래 코드는 나에게 FileNotFoundException을주었습니다.

+0

감사합니다. 나는 그것을 얻었다!! –

관련 문제