I am trying to merge two textures but when I do it adds black pixels

before merge / after merge

That’s my code:

public static Texture2D CombineImages(Rect flagRect, Texture2D backgroundTexture, Texture2D overlayTexture, Color bgColor, Color overColor, Vector2 scale, Vector2 position, float angle)
    {
        int newWidth = Mathf.RoundToInt(flagRect.width);
        int newHeight = Mathf.RoundToInt(flagRect.height);
        Texture2D newTexture = new Texture2D(newWidth, newHeight, TextureFormat.RGBA32, false);

        // Arka planı ayarla
        Color[] backgroundPixels = backgroundTexture.GetPixels();
        Color[] newPixels = new Color[newWidth * newHeight];
        for (int y = 0; y < newHeight; y++)
        {
            for (int x = 0; x < newWidth; x++)
            {
                int index = y * newWidth + x;
                Color bgColorInPos = backgroundPixels[index];
                if (bgColorInPos.a != 0)
                    newPixels[index] = bgColorInPos;
            }
        }
        newTexture.SetPixels(newPixels);

        Texture2D scaledOverlayTexture = ScaleTexture(overlayTexture, Mathf.RoundToInt(scale.x), Mathf.RoundToInt(scale.y));
        scaledOverlayTexture = RotateTexture(scaledOverlayTexture, angle);

        int startX = Mathf.FloorToInt(position.x);
        int startY = Mathf.FloorToInt(position.y);

        for (int y = 0; y < scaledOverlayTexture.height; y++)
        {
            for (int x = 0; x < scaledOverlayTexture.width; x++)
            {
                int destX = startX + x;
                int destY = startY + y;

                if (destX >= 0 && destX < newWidth && destY >= 0 && destY < newHeight)
                {
                    Color overColorInPos = scaledOverlayTexture.GetPixel(x, y);
                    if (overColorInPos.a != 0)
                    {
                        Color finalColor = new Color(overColor.r * overColorInPos.r, overColor.g * overColorInPos.g, overColor.b * overColorInPos.b, overColor.a * overColorInPos.a);   
                        newTexture.SetPixel(destX, destY, finalColor);
                    }
                }
            }
        }

        newTexture.Apply();
        return newTexture;
    }


    static Texture2D ScaleTexture(Texture2D source, int targetWidth, int targetHeight)
    {
        Texture2D result = new Texture2D(targetWidth, targetHeight, source.format, false);
        Color[] rpixels = new Color[targetWidth * targetHeight];
        float incX = (1.0f / (float)targetWidth);
        float incY = (1.0f / (float)targetHeight);

        Color fillColor = new Color(0, 0, 0, 0);

        for (int y = 0; y < targetHeight; y++)
        {
            float v = y * incY;

            for (int x = 0; x < targetWidth; x++)
            {
                float u = x * incX;

                Color pixel = source.GetPixelBilinear(u, v);

                if (pixel.a == 0f)
                {
                    pixel = fillColor;
                }

                rpixels[y * targetWidth + x] = pixel;
            }
        }

        result.SetPixels(rpixels);
        result.Apply();

        return result;
    }



    private static Texture2D RotateTexture(Texture2D originalTexture, float angle)
    {
        int width = originalTexture.width;
        int height = originalTexture.height;

        float diag = Mathf.Sqrt(width * width + height * height);
        int newWidth = Mathf.RoundToInt(diag);
        int newHeight = Mathf.RoundToInt(diag);

        Texture2D rotatedTexture = new Texture2D(newWidth, newHeight);

        float pivotX = width / 2f;
        float pivotY = height / 2f;

        float cosTheta = Mathf.Cos(Mathf.Deg2Rad * angle);
        float sinTheta = Mathf.Sin(Mathf.Deg2Rad * angle);

        for (int x = 0; x < newWidth; x++)
        {
            for (int y = 0; y < newHeight; y++)
            {
                float relX = x - pivotX;
                float relY = y - pivotY;

                float newX = cosTheta * relX + sinTheta * relY + pivotX;
                float newY = -sinTheta * relX + cosTheta * relY + pivotY;

                int srcX = Mathf.FloorToInt(newX);
                int srcY = Mathf.FloorToInt(newY);

                if (srcX >= 0 && srcX < width && srcY >= 0 && srcY < height)
                {
                    Color pixelColor = originalTexture.GetPixel(srcX, srcY);
                    rotatedTexture.SetPixel(x, y, pixelColor);
                }
                else
                {
                    rotatedTexture.SetPixel(x, y, Color.clear);
                }
            }
        }

        rotatedTexture.Apply();
        return rotatedTexture;
    }