0

ビットマップを screenSizeAverage / 3 にスケーリングする必要があります。このようにすると、時々 OutOfMemory エラーが発生します。

screenWidth = size.x; 
screenHeight = size.y;
screenSizeAverage = (screenWidth + screenHeight) / 2;
Bitmap b2 = BitmapFactory.decodeResource(getResources(), R.drawable.logoqrtz);
logoqrtz = Bitmap.createScaledBitmap(b2, screenSizeAverage / 3,screenSizeAverage / 3, true); 
protected void onDraw(Canvas canvas) {
   canvas.drawBitmap(logoqrtz, (int) (screenWidth / 2, (int) (screenHeight /2), p);
}

OutOfMemory エラーなしでこれを行う最善の方法は何ですか?

4

1 に答える 1

0

developer.android.comから

private Bitmap setPic() {
    // Get the dimensions of the View
    int targetW = size.x;
    int targetH = size.y;

    int size = ((screenWidth + screenHeight) / 2) / 3;

    // Get the dimensions of the bitmap
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
    int photoW = bmOptions.outWidth;
    int photoH = bmOptions.outHeight;

    // Determine how much to scale down the image
    int scaleFactor = Math.min(photoW/size, photoH/size);

    // Decode the image file into a Bitmap sized to fill the View
    bmOptions.inJustDecodeBounds = false;
    bmOptions.inSampleSize = scaleFactor;
    bmOptions.inPurgeable = true;

    return BitmapFactory.decodeResource(getResources(), R.drawable.logoqrtz, bmOptions);

}

あなたの場合に合わせて変更されました。

于 2016-02-23T17:36:43.600 に答える