5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

NGUIのスプライトをファイルに保存する

Last updated at Posted at 2014-10-31

なんとも変わったことをやっていますが、それなりに使いドコロはあるかもしれません。
spr1はUISpriteです。

public void ButtonClick()
{
	int width = spr1.GetAtlasSprite().width;
	int height = spr1.GetAtlasSprite().height;
	int sprx = spr1.GetAtlasSprite().x;
	int spry = spr1.GetAtlasSprite().y;
	Texture2D tmptex = new Texture2D(width,height,TextureFormat.RGBA32,false);
	Texture2D srctex = (Texture2D)spr1.atlas.texture;
	for(int y = 0; y < height; ++y) {
		for(int x = 0;x < width; ++x){
			Color c = srctex.GetPixel(x+sprx,y+(spr1.atlas.texture.height-(height+spry)));
			if(c.a == 0){
				c.r = c.g = c.b = c.a = 1;
			}
			tmptex.SetPixel(x,y,c);
		}
	}
	byte[] pngarr = tmptex.EncodeToPNG();
	Debug.Log(Application.persistentDataPath+"/test.png");
	File.WriteAllBytes(Application.persistentDataPath+"/test.png", pngarr);
}
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?