相关疑难解决方法(0)

在设备上创建位图时内存不足

我有高分辨率图像的问题.

我使用nodpi-drawable文件夹为1280x720图像,并使用此代码来缩放它.

public static Drawable scaleDrawable(Drawable d, int width, Activity cxt)
    {
        BitmapDrawable bd = (BitmapDrawable)d;

        double oldWidth = bd.getBitmap().getWidth();
        double scaleFactor = width / oldWidth;

        int newHeight = (int) (d.getIntrinsicHeight() * scaleFactor);
        int newWidth = (int) (oldWidth * scaleFactor);

        Drawable drawable = new BitmapDrawable(cxt.getResources(),MainScreen.getResizedBitmap(bd.getBitmap(),newHeight,newWidth));

        BitmapDrawable bd2 = (BitmapDrawable)drawable;

        return  drawable;
    }

    public static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) { 

        int width = bm.getWidth(); 
        int height = bm.getHeight(); 

        float scaleWidth = ((float) newWidth) / width;
        float scaleHeight = …
Run Code Online (Sandbox Code Playgroud)

android bitmap out-of-memory

2
推荐指数
1
解决办法
2849
查看次数

标签 统计

android ×1

bitmap ×1

out-of-memory ×1