Example #1
0
    //jpg转为透明png
    static public Texture2D ConvertJpg2AlphaPng(Texture2D tex)
    {
        int        w             = tex.width;
        int        h             = tex.height;
        Texture2D  texRet        = new Texture2D(w, h, TextureFormat.ARGB32, false);
        ColorImage colorImageRet = new ColorImage();

        colorImageRet.Init(texRet);

        ColorImage colorImage = new ColorImage();

        colorImage.Init(tex);


        for (int i = 0; i < w; i++)
        {
            for (int j = 0; j < h; j++)
            {
                Vector2 pt    = new Vector2(i, j);
                Color   color = colorImage.GetImageColorOrigin(pt);
                color.a = 1f;
                colorImageRet.SetImageColor(pt, color);
            }
        }
        colorImageRet.UpdateTexture();

        return(texRet);
    }
Example #2
0
    static public Rect GetRectNotAlpha(Texture2D tex)
    {
        int        fillXLeft = tex.width;
        int        fillXRight = 0;
        int        fillYBottom = tex.height;
        int        fillYTop = 0;
        int        x, y, w, h;
        ColorImage colorImage = new ColorImage();

        colorImage.Init(tex);
        for (int j = 0; j < tex.height; j++)
        {
            for (int i = 0; i < tex.width; i++)
            {
                Vector2 pt    = new Vector2(i, j);
                Color   color = colorImage.GetImageColorOrigin(pt);
                if (color.a >= 1f)
                {
                    x = i;
                    y = j;
                    if (x < fillXLeft)
                    {
                        fillXLeft = x;
                    }
                    if (x > fillXRight)
                    {
                        fillXRight = x;
                    }


                    if (y < fillYBottom)
                    {
                        fillYBottom = y;
                    }
                    if (y > fillYTop)
                    {
                        fillYTop = y;
                    }
                }
            }
        }
        Debug.Log("tex.width=" + tex.width + " fillXLeft=" + fillXLeft + " fillXRight=" + fillXRight);
        return(new Rect(fillXLeft, fillYBottom, (fillXRight - fillXLeft), (fillYTop - fillYBottom)));
    }
Example #3
0
    Texture2D CreateTexTureBg(int w, int h)
    {
        Texture2D tex = new Texture2D(w, h, TextureFormat.ARGB32, false);
        // return tex;
        ColorImage crImage = new ColorImage();

        crImage.Init(tex);
        for (int j = 0; j < h; j++)
        {
            for (int i = 0; i < w; i++)
            {
                Vector2 pttmp    = new Vector2(i, j);
                Color   colorpic = new Color(0f, 0f, 0f, 0f);
                crImage.SetImageColor(pttmp, colorpic);
            }
        }

        crImage.UpdateTexture();

        return(tex);
    }