2017-12-11 10 views
1

사진을 찍을 수있는 카메라 앱을 만들었지 만 특정 (미리 설정된) 너비/높이와 종횡비로 저장하고 싶습니다.미리 설정된 종횡비와 너비/높이로 이미지 자르기

예 :

Example crop image with margins

  • 레드 : 나는 시도했다

마진 : 오래 된 그림 (소스)

  • 녹색 : 새 그림 빨간색과 녹색 사이
  • 다음 (운없이) :

    BitmapFactory.Options bmOptions = new BitmapFactory.Options(); 
        bitmap = BitmapFactory.decodeFile(editPhotoFile.getAbsolutePath(), bmOptions); 
        bitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth(), bitmap.getHeight(), true); 
        Bitmap croppedBmp = Bitmap.createBitmap(bitmap, margin, margin, bitmap.getWidth() - margin, bitmap.getHeight() - margin); 
    

    여백을 사용하여 왼쪽 (첫 번째 여백) 및 위쪽 (두 번째 여백)의 픽셀을 일정하게하고 전체 너비와 높이를 동일하게 자르려고했습니다. 작동 안함.

    Github에는 일부 라이브러리도 있지만 이미지를 선택하고 편집 할 수 있습니다. 수동 편집이 필요하지 않으며 자르기 여백을 미리 설정하고 싶습니다. 또한 Library 'ArthurHub/Android-Image-Cropper'

  • Library 'Yalantis/uCrop'

    • , 스택 오버플로 그냥 인터넷 검색이나 나에게 운을주지 않는다 튜토리얼을 찾아 여기에 가능한 솔루션을 제공합니다. 검색 쿼리 :

      자바 안드로이드 작물 이미지

      자바 안드로이드 작물 영상 튜토리얼

      누가 나를 도울 수 있습니까?

  • +0

    은 그래서 당신은 사용자가 이미지 croping..portion를 편집 할 싶지 않아? – rafsanahmad007

    +0

    Nope. 이미지를 직접 자르므로 각 장치에서 이미지의 비율이 동일합니다. 일부 장치에는 3 : 4 센서가 있고 다른 장치에는 9:16 또는 16 : 9 등이 있습니다. 그게 이유야. –

    답변

    1

    나는 거기에 또한 가고있다. 몇 주 동안 고생했지만 두뇌가 깨끗 해졌다. 모든 것이 잘되고 있었지만, 그림/이미지를 장치에 저장하지는 않았다.

    여백이 작동 중입니다.

    내일이 게시물을 내가 찾은 해결책으로 업데이트/편집 할 것입니다.

    업데이트 :

    // get String with path to file from other activity and make new File of it 
        File editPhotoFile = new File(globalFileString); 
        BitmapFactory.Options bmOptions = new BitmapFactory.Options(); 
        bitmap = BitmapFactory.decodeFile(photoFile.getAbsolutePath(), bmOptions); 
    
        // crop the bitmap with new margins: bitmap, left, top, width, height 
        Bitmap croppedBmp = Bitmap.createBitmap(bitmap, marginLeft, marginTop, bitmapHeight, bitmapWidth); 
    
        // save bitmap to new file 
        FileOutputStream out = null; 
        File mediaFile; 
        try { 
         mediaFile = new File(globalFileString); 
         out = new FileOutputStream(mediaFile); 
         croppedBmp.compress(Bitmap.CompressFormat.JPEG, 100, out); 
        } catch (Exception e) { 
         e.printStackTrace(); 
        } finally { 
         try { 
          if (out != null) { 
           out.close(); 
          } 
         } catch (IOException e) { 
          e.printStackTrace(); 
         } 
        }