Sunday, July 14, 2019

Android -Insert one image into another's transparent pixels

In Android, I'm trying to create two images (in this case, the Bitmap object) in FrameLayout. An image is placed on top, the other image is inserted beneath it in the first pixel transparent image.
Android -Insert one image into another's transparent pixels


Currently, I'm trying to use Bitmap.getPixel () to determine the transparent pixels.
for (int i = 0; i < image_count; i++)
{
    //load page from internal memory
    topImages[i] = getImage("p"+i+".png");
    for (int x = 0; x < topImages[i].getWidth(); x++)
    {
        for (int y = 0; y < topImages[i].getHeight(); y++)
        {
            if (topImages[i].getPixel(x, y) == Color.TRANSPARENT)
            {
                bottomX[i] = x;
                bottomY[i] = y;
                break;
            }
        }
    }
}
Then I add the image to the frame layout, using two ImageView and use these values ​​to position the image below:
bottomView.setTranslationX(bottomX[position]);
bottomView.setTranslationY(bottomY[position]);
However, the location of the pictures below are incorrect, usually due to down and right margins of different (but always the same) for each certain picture. I also tried setX () and sety (), as well as the parameters used to set values ​​and LEFT TOP similar, with the same result). What can I do to ensure that consistent position, with the top left corner at (or near) the first pixel transparent? 

1 comment: