Pergunta

Estou tentando diminuir um bitmap que contém transparência. Infelizmente, todos os três métodos que tentei resultam em branco, onde deve haver total transparência. Eu gostaria de manter a transparência.

O bitmap que estou escalando é sempre quadrado, então minhas funções assumem que:

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;
}
Foi útil?

Solução

Parece gráfico.drawbitmap (...) usa graphics.drawrgb (...) em vez de graphics.drawargb (...)

A distinção é se o canal alfa é usado ou não para desenhar o bitmap. Eu tentei usar gráficos.drawargb (...) diretamente para outro trabalho de bitmap transparente que eu tenho feito, e isso fez a diferença.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top