0

選択した境界に画像を合わせるために「拡張」ボタンを実装しようとしています。

public void extendS(View v){
        ImageView iv = current;
        double width = gallery.getWidth();
        double hight= gallery.getHeight();

        double aspect = (width+0)/(hight+0);
        Log.d("aspect", "w: "+width+" h: "+hight+" a: "+aspect);
        if (aspect>1){
            hight/=aspect;
        }else{
            width*=aspect;
        }
        Bitmap b = ((BitmapDrawable) iv.getDrawable()).getBitmap();
//      Matrix matrix = new Matrix();
        Log.d("aspect", "w: "+width+" h: "+hight+" a: "+aspect);
         Bitmap scale = Bitmap.createBitmap(b, 0, 0, (int)width, (int)hight);
         iv.setImageBitmap(scale);

私が受け取ったエラー: 07-16 12:26:36.855: E/AndroidRuntime(12647): 原因: java.lang.IllegalArgumentException: y + 高さは <= bitmap.height() でなければなりません視点

4

2 に答える 2

1
public static Bitmap resizeBitmap(Bitmap photo, float x, float y) {

    try {
        // get current bitmap width and height
        int width = photo.getWidth();
        int height = photo.getHeight();

        // determine how much to scale
        float scaleWidth = x / width;
        float scaleHeight = y / height;

        // create the matrix for the manipulation
        Matrix matrix = new Matrix();
        // resize the bitmap
        matrix.postScale(scaleWidth, scaleHeight);

        // recreate the new bitmap
        Bitmap resizebitmap = Bitmap.createBitmap(photo, 0, 0, width,
                height, matrix, false);
        return resizebitmap;

    } catch (NullPointerException e) {
        e.printStackTrace();
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
        System.gc();
    }
    return null;
}
于 2013-07-16T09:31:22.713 に答える