Beispiel #1
0
    public static void AlphaMerge(Texture2D rgbTex, Texture2D alphaTex)
    {
        int width  = rgbTex.width;
        int height = rgbTex.height;

        if (width > 0 && height > 0 && alphaTex.width == width && alphaTex.height == height)
        {
            Color32[] rgbPixels   = rgbTex.GetPixels32();
            Color32[] alphaPixels = alphaTex.GetPixels32();

            Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppRgb);
            bitmap.MakeTransparent();
            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    Color32 rgbPixel   = rgbPixels[i * width + j];
                    Color32 alphaPixel = alphaPixels[i * width + j];
                    bitmap.SetPixel(j, height - 1 - i, System.Drawing.Color.FromArgb(alphaPixel.r, rgbPixel.r, rgbPixel.g, rgbPixel.b));
                }
            }

            ImageTGA imageTga = new ImageTGA();

            imageTga.Image = bitmap;
            string path = Application.dataPath + AssetDatabase.GetAssetPath(rgbTex.GetInstanceID()).Substring("Assets".Length);
            imageTga.SaveImage(path);

            string alphaPath = Application.dataPath + AssetDatabase.GetAssetPath(alphaTex.GetInstanceID()).Substring("Assets".Length);
            File.Delete(alphaPath);
        }
    }
Beispiel #2
0
    public static void AlphaStrip(Texture2D tex)
    {
        int width  = tex.width;
        int height = tex.height;

        Color32[] pixels = tex.GetPixels32();

        Bitmap bitmapRgb   = new Bitmap(width, height, PixelFormat.Format24bppRgb);
        Bitmap bitmapAlpha = new Bitmap(width, height, PixelFormat.Format24bppRgb);

        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                Color32 pixel = pixels[y * width + x];
                bitmapRgb.SetPixel(x, height - 1 - y, System.Drawing.Color.FromArgb(pixel.r, pixel.g, pixel.b));
                bitmapAlpha.SetPixel(x, height - 1 - y, System.Drawing.Color.FromArgb(pixel.a, pixel.a, pixel.a));
            }
        }

        ImageTGA imageTga = new ImageTGA();

        imageTga.Image = bitmapRgb;
        string rgbPath = Application.dataPath + AssetDatabase.GetAssetPath(tex.GetInstanceID()).Substring("Assets".Length);

        imageTga.SaveImage(rgbPath);

        imageTga.Image = bitmapAlpha;
        string alphaPath = GetAlphaPath(rgbPath);

        imageTga.SaveImage(alphaPath);
    }