0

ユーザーが画面に触れて写真の上に「ステッカー」を配置できる画像編集アプリを作成しています。

私のステッカーはすべて、透明にしたい緑色の背景 (0、255、0) を持っています。ただし、ピクセルは透明ではなく、代わりに黒になります。

透明なビットマップをロードするコードは次のとおりです。

private Bitmap transparentBitmap(int id)
{
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inMutable = true;

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), id, bmOptions);

    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    int[] pixels = new int[width * height];

    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);

    for (int y = 0; y < height; y++)
    {
        for (int x = 0; x < width; x++)
        {
            int index = y * width + x;

            if (pixels[index] == Color.GREEN)
            {
                pixels[index] = Color.argb(0, 0, 0, 0);
            }
        }
    }

    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);

    return bitmap;
}

アプリの最初にすべてのステッカーをロードし、ユーザーが画面のどこかに触れると、Assets クラスの静的ビットマップからグラフィックがコピーされます。

private Bitmap getGFX(stickerTypes type)
{
    switch(type)
    {
    case sweatDrop: return Assets.sweatDrop_GFX.copy(Config.ARGB_4444, true);
    case veins: return Assets.veins_GFX.copy(Config.ARGB_4444, true);
    default: return null; 
    }
}

私が言ったように、私の実際のステッカーは透明な背景ではなく、黒い背景で表示されます。それらは .png として保存されます。

私が考えることができる唯一の説明は、ユーザーの写真の背景ではなく、アクティビティの背景に対してステッカーの背景ピクセルが透明に設定されているということですが、それはあまり意味がありません。アクティビティは黒ではなくオレンジです。

4

2 に答える 2

0

現在、アルファ成分Colors.argb(...)をゼロに設定しています

pixels[index] = Color.argb(0, 0, 0, 0);

代わりに、最大アルファに設定します。

pixels[index] = Color.argb(255, 0, 0, 0);
于 2013-12-01T01:47:57.777 に答える
0

ペイントでピクセルを作成し、プロパティ「set Alpha」を変更して透明にします

それがうまくいくことを願っています!

于 2013-07-22T19:37:38.317 に答える