2016-11-05 5 views
0

아주 기본적인 질문이지만이 문제를 해결하기 위해 노력하고 있습니다. 나는 이미지 - 스케치 모바일 애플 리케이션에서 일하고있다. 나는 이제 모든 작업을 완료했다. 단지 결과 비트 맵 이미지를 내부 메모리에 저장하려고한다. 이미지 저장 목적을 위해 "mageStore()"메소드를 작성했다. 거기에 코드를 작성한다. 나는 너에게 매우 감사 할 것이다. 당신이 필요 귀하의 기능에안드로이드의 내부 저장소에 비트 맵을 저장하는 방법

`private class ImageProcessingTask extends AsyncTask<Bitmap, Void, Bitmap> { 
    private ProgressDialog abhanDialog = null; 
    private Bitmap returnedBitmap = null; 

    @Override 
    protected void onPreExecute() { 
     returnedBitmap = null; 
     abhanDialog = new ProgressDialog(AbhanActivity.this); 
     abhanDialog.setMessage(getString(R.string.please_wait)); 
     abhanDialog.setCancelable(false); 
     abhanDialog.show(); 
    } 

    @Override 
    protected Bitmap doInBackground(Bitmap... params) { 
     final Bitmap sketched = AbhanSketch.createSketch(params[0]); 
     final Bitmap gaussianBitmap = AbhanEffects.applyGaussianBlur(sketched); 
     final Bitmap sepiaBitmap = AbhanEffects.sepiaTonnedBitmap(gaussianBitmap, 151, 0.71, 
       0.71, 0.76); 
     returnedBitmap = AbhanEffects.sharpenBitmap(sepiaBitmap, 0.81); 
     return returnedBitmap; 
    } 

    @Override 
    protected void onPostExecute(Bitmap result) { 
     if (abhanDialog != null && abhanDialog.isShowing()) { 
      abhanDialog.cancel(); 
     } 
     if (result != null) { 
      mImageView.setImageBitmap(result); 
      mImageView.buildDrawingCache(); 
      bmap = mImageView.getDrawingCache(); 
      storeImage(bmap); 
      isImage = false; 
      enableButton(); 
      final boolean isFileDeleted = Utils.deleteFile(mPath); 
      if (DEBUG) { 
       android.util.Log.i(TAG, "File Deleted: " + isFileDeleted); 
      } 
     } 
    } 
} 

private void storeImage(Bitmap image) { 
    ...please enter code here for image storing 
}` 
+0

File pictureFile = getOutputMediaFile(); \t \t 경우 (pictureFile == NULL) { \t \t \t Log.d (TAG, \t \t \t \t \t "오류 저장 권한을 확인, 미디어 파일을 생성 :"); // e.getMessage()); \t \t \t return; \t \t} \t \t 시도 { \t \t \t FileOutputStream에의 FOS = 새로운 FileOutputStream에 (pictureFile); \t \t \t image.compress (Bitmap.CompressFormat.PNG, 90, fos); \t \t \t Toast.makeText (AbhanActivity.this, "stored", Toast.LENGTH_SHORT) .show(); \t \t \t fos.close(); \t \t} catch (FileNotFoundException e) { \t \t \t Log.d (TAG, "파일을 찾을 수 없음 :"+ e.getMessage()); \t \t} catch (IOException e) { \t \t \t Log.d (TAG, "오류 액세스 파일 :"+ e.getMessage()); \t \t –

+0

위의 코드를 이미지 저장 목적으로 사용하고 있습니다. –

+0

내 대답 참조 http://stackoverflow.com/questions/37967711/how-to-take-screenshot-for-android-surface-view/37968834#37968834 , 이미지 뷰가 상주하는 상위 뷰를 렌더링하고 스크린 샷으로 가져와야합니다. 나머지는 거기에 언급되어 있습니다. – Radhey

답변

0

갤러리 이미지에

private String Saveme(Bitmap bitmapImage, String img_name){ 
      ContextWrapper cw = new ContextWrapper(getApplicationContext()); 
      // path to /data/data/yourapp/app_data/imageDir 
      File directory = cw.getDir("imageDir", Context.MODE_PRIVATE); 
      // Create imageDir 
      File mypath=new File(directory,img_name); 

      FileOutputStream fos = null; 
      try {   
       fos = new FileOutputStream(mypath); 
      // Use the compress method on the BitMap object to write image to the OutputStream 
       bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos); 
      } catch (Exception e) { 
        e.printStackTrace(); 
      } finally { 
       try { 
        fos.close(); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 
      } 
      return directory.getAbsolutePath(); 
     } 

을 다음 Saveme 다음 코드

String path = Saveme(image,"image_name.jpg"); 
//path contains the full path to directory where all your images get stored internaly lolz but privately 

for gallery 
Saveme(image,"my image","my image test for gallery save"); 

과 해상력을() 함수는 쓰기 미디어 저장소에서 표시됩니다 미디어 저장소에 이미지를 저장하려면 다음 코드가 도움이 될 수 있습니다.

,210
+0

답장을 보내 주셔서 감사합니다 .. –

+0

나는이 방법을 시도했지만 어떤 결과 이미지도 찾지 못했습니다. 단지 내부 메모리가없는 sdcard 만 있습니다. –

+0

"갤러리에 이미지를 저장하는 방법" –

0

여기 함수 당신은 생략하거나 필요에 따라이 줄

bitmap = Bitmap.createScaledBitmap(bitmap, 400, (int) (bitmap.getHeight() * (400.0/bitmap.getWidth())) ,false); 

을 편집 할 수 있습니다

private void storeImage(Bitmap image) { 

    File sdcard = Environment.getExternalStorageDirectory() ; 

    File folder = new File(sdcard.getAbsoluteFile(), "YOUR_APP_DIRECTORY"); 
    if(!folder.exists()) 
     folder.mkdir(); 
    File file = new File(folder.getAbsoluteFile(), "IMG_" + System.currentTimeMillis() + ".jpg") ; 
    if (file.exists()) 
     file.delete(); 

    try { 
     FileOutputStream out = new FileOutputStream(file); 

     bitmap = Bitmap.createScaledBitmap(bitmap, 400, (int) (bitmap.getHeight() * (400.0/bitmap.getWidth())) ,false); 

     bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); 
     out.flush(); 
     out.close(); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

내부에 누락 된 코드입니다.

관련 문제