Domanda

Sto cercando di ridimensionare una bitmap che contiene trasparenza. Purtroppo, tutti e tre i metodi che ho provato risultato in bianco dove ci dovrebbe essere la massima trasparenza. Vorrei mantenere la trasparenza.

La bitmap Sono scala è sempre quadrata, quindi le mie funzioni presuppongono che:

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;
}
È stato utile?

Soluzione

Sembra che Graphics.drawBitmap (...) usa Graphics.drawRGB (...) invece di Graphics.drawARGB (...)

La distinzione è se il canale alfa è utilizzato per disegnare la bitmap. Ho provato con Graphics.drawARGB (...) direttamente per qualche altro lavoro bitmap trasparente che ho fatto, e che ha fatto la differenza.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top