本文介绍了缩放位图和preserveα,黑莓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图缩小包含透明位图。不幸的是,所有这三种方法我试过在白色的结果,其中应该有充分的透明度。我想保持透明度。

我缩放位图始终是方形,所以我的功能假设:

 私有静态位图量程1(INT边缘,最终的位图资源){
    INT系数=
        边缘== 0? Fixed32.ONE:Fixed32.div(res.getHeight(),EDGE);
    位图缩放= PNGEn codedImage.en code(RES)。
                        scaleImage32(因子,因子).getBitmap();
    返回比例;
}私有静态位图scale2(INT边缘,最终的位图资源){
    位图VAL =新位图(边,边缘);
    val.createAlpha(Bitmap.ALPHA_BITDEPTH_8BPP);
    res.scaleInto(VAL,Bitmap.FILTER_BILINEAR);
    返回VAL;
}私有静态位图scale3(INT边缘,最终的位图资源){
    位图VAL =新位图(边,边缘);
    val.createAlpha(Bitmap.ALPHA_BITDEPTH_8BPP);
    图形G =新的图形(VAL);
    INT [] pathX =新INT [] {0,0 +边缘,0 +边缘,0};
    INT [] pathY =新INT [] {0,0,0 +边缘,0 +边缘};
    字节[] = pathPointTypes新的字节[] {
        Graphics.CURVEDPATH_END_POINT,Graphics.CURVEDPATH_END_POINT,
        Graphics.CURVEDPATH_END_POINT,Graphics.CURVEDPATH_END_POINT};
    INT系数=
        边缘== 0? Fixed32.ONE:Fixed32.div(res.getHeight(),EDGE);
    g.drawTexturedPath(pathX,pathY,pathPointTypes,空,
            0,0,因素,Fixed32.toFP(0),Fixed32.toFP(0),因素,水库);
    返回VAL;
}


解决方案

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

的区别是alpha通道是否被用于绘制位图。我一直在使用直接Graphics.drawARGB(...)对于其他一些透明位图的工作​​,我一直在做尝试,这让的区别。

I am trying to scale down a Bitmap that contains transparency. Unfortunately, all three methods I've tried result in white where there should be full transparency. I would like to maintain the transparency.

The bitmap I am scaling is always square, so my functions assume that:

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;
}
解决方案

It looks like Graphics.drawBitmap(...) uses Graphics.drawRGB(...) instead of Graphics.drawARGB(...)

The distinction is whether or not the alpha channel is used to draw the bitmap. I've tried using Graphics.drawARGB(...) directly for some other transparent bitmap work I've been doing, and that made the difference.

这篇关于缩放位图和preserveα,黑莓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 04:45
查看更多