Android 如何用自己的尺寸绘制位图?

Android 如何用自己的尺寸绘制位图?,android,bitmap,Android,Bitmap,我想根据我稍后设置的尺寸画一点。但我唯一熟悉的方法是: canvas.drawBitmap(test, canvas.getWidth()/2 - test.getWidth()/2, canvas.getHeight()/2 - test.getHeight()/2, null); 它只根据图像尺寸绘制位图,所以我的问题是,是否有其他方法绘制不同尺寸的位图,或者只是一种改变它的方法 谢谢 使用以下代码根据您选择的尺寸调整位图的大小: public static Bitmap decodeS

我想根据我稍后设置的尺寸画一点。但我唯一熟悉的方法是:

canvas.drawBitmap(test, canvas.getWidth()/2 - test.getWidth()/2, canvas.getHeight()/2  - test.getHeight()/2, null);
它只根据图像尺寸绘制位图,所以我的问题是,是否有其他方法绘制不同尺寸的位图,或者只是一种改变它的方法


谢谢

使用以下代码根据您选择的尺寸调整位图的大小:

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;
 }

[使用此方法:-如果您阅读文档,您可以看到画布的7种方法。drawBitmap:是的,我看到了其他方法,但我使用哪一种方法?