-1

将 RGB 图像转换为位图

public static Bitmap rgbToBitmap(int[] rgb, int width, int height) {
    if (rgb == null) throw new NullPointerException();

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
    bitmap.setPixels(rgb, 0, width, 0, 0, width, height);
    return bitmap;
}
4

2 回答 2

1

试试这种方式:

 Bitmap bmp = Bitmap.createBitmap(frameWidth, frameHeight, Bitmap.Config.ARGB_8888); 

编辑:

您可以out of memory使用以下方法解决问题:

 public static Bitmap shrinkBitmap(String p_file, int p_width, int p_height)
{
    BitmapFactory.Options m_bmpFactoryOptions = new BitmapFactory.Options();
    m_bmpFactoryOptions.inJustDecodeBounds = true;
    Bitmap m_bitmap = BitmapFactory.decodeFile(p_file, m_bmpFactoryOptions);        
    int m_heightRatio =
            (int) Math.ceil(m_bmpFactoryOptions.outHeight / (float) p_height);
    int m_widthRatio =
            (int) Math.ceil(m_bmpFactoryOptions.outWidth / (float) p_width);        
    if (m_heightRatio > 1 || m_widthRatio > 1)
    {
        if (m_heightRatio > m_widthRatio)
        {
            m_bmpFactoryOptions.inSampleSize = m_heightRatio;
        }
        else
        {
            m_bmpFactoryOptions.inSampleSize = m_widthRatio;
        }
    }       
    m_bmpFactoryOptions.inJustDecodeBounds = false;
    m_bitmap = BitmapFactory.decodeFile(p_file, m_bmpFactoryOptions);
    return m_bitmap;
}

希望它会帮助你。

于 2013-01-09T10:43:09.727 回答
0

尝试将 Bitmap.createScaledBitmap() 与设备宽度和高度一起使用,图像超出了内存预算

于 2013-01-10T06:00:03.653 回答