在BlackBerry上扩展位图并保留alpha

时间:2010-11-21 18:40:24

标签: blackberry image-processing alpha

我正在尝试缩小包含透明度的位图。不幸的是,我尝试过的所有三种方法都会导致白色应该是完全透明的。我想保持透明度。

我缩放的位图总是方形的,所以我的函数假定:

private static Bitmap scale1(int edge, final Bitmap res) {
    int factor = 
        edge == 0 ? Fixed32.ONE : Fixed32.div(res.getHeight(), edge);
    Bitmap scaled = PNGEncodedImage.encode(res).
                        scaleImage32(factor, factor).getBitmap();
    return scaled;
}

private static Bitmap scale2(int edge, final Bitmap res) {
    Bitmap val = new Bitmap(edge,edge);
    val.createAlpha(Bitmap.ALPHA_BITDEPTH_8BPP);
    res.scaleInto(val, Bitmap.FILTER_BILINEAR);
    return val;
}

private static Bitmap scale3(int edge, final Bitmap res) {
    Bitmap val = new Bitmap(edge,edge);
    val.createAlpha(Bitmap.ALPHA_BITDEPTH_8BPP);
    Graphics g = new Graphics(val);
    int[] pathX = new int[] {0, 0+edge, 0+edge, 0};
    int[] pathY = new int[] {0, 0, 0+edge, 0+edge};
    byte[] pathPointTypes = new byte[] {
        Graphics.CURVEDPATH_END_POINT,Graphics.CURVEDPATH_END_POINT,
        Graphics.CURVEDPATH_END_POINT,Graphics.CURVEDPATH_END_POINT};
    int factor = 
        edge == 0 ? Fixed32.ONE : Fixed32.div(res.getHeight(), edge);
    g.drawTexturedPath(pathX, pathY, pathPointTypes, null,
            0, 0, factor, Fixed32.toFP(0), Fixed32.toFP(0), factor, res);
    return val;
}

1 个答案:

答案 0 :(得分:2)

看起来Graphics.drawBitmap(...)使用Graphics.drawRGB(...)而不是Graphics.drawARGB(...)

区别在于alpha通道是否用于绘制位图。我已经尝试将Graphics.drawARGB(...)直接用于我一直在做的其他透明位图工作,这就产生了不同。