2014-07-08 5 views
0

나중에 설정할 치수에 따라 조금씩 그려 보겠습니다. 그러나와 familliar 수있는 ​​유일한 방법 임은 하나를 다음입니다 : 내 질문은, 그래서, 다른 차원하거나하는 방법으로 비트 맵을 그릴 수있는 또 다른 방법은 이미지 차원에 비트 맵 accordign을 그릴 내 차원으로 비트 맵을 그리는 방법은 무엇입니까?

canvas.drawBitmap(test, canvas.getWidth()/2 - test.getWidth()/2, canvas.getHeight()/2 - test.getHeight()/2, null); 

그것을 바꿀?

감사합니다. 코드 아래

+0

[사용이 하나 - http://stackoverflow.com/questions/23346412/draw-bitmap-on-canvas-with-original -dimension –

+0

설명서를 읽으면 canvas.drawBitmap에 대한 7 가지 방법을 볼 수 있습니다. http://developer.android.com/reference/android/graphics/Canvas.html –

+0

예, 다른 방법을 보았습니다. 용도? – Pachu

답변

0

를 사용하여 사용자가 선택한 크기와 비트 맵의 ​​크기를 조정하려면 :

public static Bitmap decodeSampledBitmapFromPath(String path, int reqWidth, 
      int reqHeight) { 

    final BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inJustDecodeBounds = true; 
    BitmapFactory.decodeFile(path, options); 

    options.inSampleSize = calculateInSampleSize(options, reqWidth, 
      reqHeight); 

    // Decode bitmap with inSampleSize set 
    options.inJustDecodeBounds = false; 
    Bitmap bmp = BitmapFactory.decodeFile(path, options); 
    return bmp; 
} 

public static int calculateInSampleSize(BitmapFactory.Options options, 
     int reqWidth, int reqHeight) { 

    final int height = options.outHeight; 
    final int width = options.outWidth; 
    int inSampleSize = 1; 

    if (height > reqHeight || width > reqWidth) { 
     if (width > height) { 
       inSampleSize = Math.round((float) height/(float) reqHeight); 
     } else { 
       inSampleSize = Math.round((float) width/(float) reqWidth); 
     } 
    } 
return inSampleSize; 
} 
관련 문제