public void create(int width, int height, TextureFormat texFormat = TextureFormat.ARGB32) { this.width = width; this.height = height; texture = new Texture2D(width, height, texFormat, false); if (texture == null) { PGraphics.debuglogWaring("create: new Texture2D <failed>"); return; } clear(new Color(0, 0, 0, 0)); }
public bool loadPixels() { if (!texture) { return(false); } pixels = texture.GetPixels32(); if (pixels == null) { PGraphics.debuglogWaring("loadPixels:GetPixels32 <failed>"); return(false); } else { return(true); } }
bool loadFromLocalFile(string path) { if (!File.Exists(path)) { PGraphics.debuglogWaring("loadImage:loadFromLocalFile <NotFound> " + path);; return(false); } byte[] bytes = null; FileStream fs = new FileStream(path, FileMode.Open); using (BinaryReader bin = new BinaryReader(fs)) { bytes = bin.ReadBytes((int)bin.BaseStream.Length); } Texture2D tex = new Texture2D(0, 0); tex.LoadImage(bytes); set(tex); if (tex != null) { PGraphics.debuglog("loadImage:loadFromLocalFile " + path); if (width == 0) { width = texWidth; } if (height == 0) { height = texHeight; } } else { PGraphics.debuglogWaring("loadImage:loadFromLocalFile <Failed> " + path); } return(tex != null); }
bool loadFromResources(PGraphics g, string path) { string resPath = g.getResourceName(path); Texture2D tex = Resources.Load(resPath) as Texture2D; set(tex); if (tex != null) { PGraphics.debuglog("loadImage:loadFromResources " + resPath); if (width == 0) { width = texWidth; } if (height == 0) { height = texHeight; } } else { PGraphics.debuglogWaring("loadImage:loadFromResources <Failed> " + resPath); } return(tex != null); }