public static Polygon MakePolygon(LImage image) { if (image == null) { throw new RuntimeException("Image is null !"); } return MakePolygon(image.GetIntPixels(), image.GetWidth(), image.GetHeight()); }
public static LImage CreateImage(InputStream ins) { LImage image = null; try { image = new LImage(); image.m_data = Texture2D.FromStream(GL.device, ins); image.width = image.m_data.Width; image.height = image.m_data.Height; image.isExt = true; image.CheckAlpha(); } catch (Exception ex) { Loon.Utils.Debugging.Log.Exception(ex); } finally { if (ins != null) { try { ins.Close(); ins = null; } catch (Exception) { } } } return(image); }
public PShadowEffect(string fileName, LImage back, int x, int y, int w, int h) : this(LImage.CreateImage(fileName), back, x, y, w, h) { }
private void init(int width, int height, bool alpha) { this.width = width; this.height = height; this.hasAlpha = alpha; this.buffer = LImage.CreateImage(width, height, alpha); this.pixels = buffer.GetPixels(); this.finalPixels = (Color[])CollectionUtils.CopyOf(pixels); }
public void Dispose() { this.isClose = true; if (buffer != null) { buffer.Dispose(); buffer = null; } }
public static LImage DrawCropImage(LImage image, int x, int y, int objectWidth, int objectHeight) { LImage buffer = LImage.CreateImage(objectWidth, objectHeight, true); LGraphics g = buffer.GetLGraphics(); g.DrawImage(image, 0, 0, objectWidth, objectHeight, x, y, objectWidth, objectHeight); g.Dispose(); return buffer; }
public static LImage CreateImage(int width, int height, SurfaceFormat format) { LImage image = new LImage(); image.m_data = new RenderTarget2D(GL.device, width, height, false, format, DepthFormat.None, 0, RenderTargetUsage.PreserveContents); image.width = image.m_data.Width; image.height = image.m_data.Height; image.CheckAlpha(); return(image); }
public static LImage DrawCropImage(LImage image, int x, int y, int objectWidth, int objectHeight) { LImage buffer = LImage.CreateImage(objectWidth, objectHeight, true); LGraphics g = buffer.GetLGraphics(); g.DrawImage(image, 0, 0, objectWidth, objectHeight, x, y, objectWidth, objectHeight); g.Dispose(); return(buffer); }
public static LImage DrawClipImage(LImage image, int objectWidth, int objectHeight, int x1, int y1, int x2, int y2) { LImage buffer = LImage.CreateImage(objectWidth, objectHeight, true); LGraphics g = buffer.GetLGraphics(); g.DrawImage(image, 0, 0, objectWidth, objectHeight, x1, y1, x2 - x1, y2 - y1); g.Dispose(); return buffer; }
public LImage Clone() { LImage image = new LImage(); image.width = width; image.height = height; image.hasAlpha = hasAlpha; image.m_data = m_data; image.fileName = fileName; image.isExt = isExt; return(image); }
public static LImage DrawClipImage(LImage image, int objectWidth, int objectHeight, int x1, int y1, int x2, int y2) { LImage buffer = LImage.CreateImage(objectWidth, objectHeight, true); LGraphics g = buffer.GetLGraphics(); g.DrawImage(image, 0, 0, objectWidth, objectHeight, x1, y1, x2 - x1, y2 - y1); g.Dispose(); return(buffer); }
public static LImage CreateImage(Color[] pixels, int width, int height, bool hasAlpha) { LImage image = new LImage(); image.hasAlpha = hasAlpha; image.width = width; image.height = height; int size = width * height; Texture2D texture = new Texture2D(GL.device, width, height); texture.SetData <Color>(pixels); image.m_data = texture; return(image); }
public static LImage CreateImage(LImage image, int x, int y, int width, int height, int transform) { LImage result = new LImage(); if (transform < 4) { result.m_data = new Texture2D(GL.device, width, height, false, SurfaceFormat.Color); } else { result.m_data = new Texture2D(GL.device, height, width, true, SurfaceFormat.Color); } result.width = image.m_data.Width; result.height = image.m_data.Height; result.CheckAlpha(); return(result); }
public static LImage GetResize(LImage image, int w, int h) { if (image == null) { return null; } if (image.width == w && image.height == h) { return image; } LImage result = LImage.CreateImage(w, h, image.HasAlpha()); LGraphics g = result.GetLGraphics(); g.DrawImage(image, 0, 0, w, h, 0, 0, image.GetWidth(), image.GetHeight()); g.Dispose(); return result; }
public static LImage GetResize(LImage image, int w, int h) { if (image == null) { return(null); } if (image.width == w && image.height == h) { return(image); } LImage result = LImage.CreateImage(w, h, image.HasAlpha()); LGraphics g = result.GetLGraphics(); g.DrawImage(image, 0, 0, w, h, 0, 0, image.GetWidth(), image.GetHeight()); g.Dispose(); return(result); }
internal static LImage NewImage(Texture2D tex2d) { int size = tex2d.Width * tex2d.Height; Color[] pixels = new Color[size]; tex2d.GetData <Color>(pixels); LImage image = new LImage(); Texture2D newTex2d = new Texture2D(GL.device, tex2d.Width, tex2d.Height); newTex2d.SetData <Color>(pixels); image.m_data = newTex2d; image.width = image.m_data.Width; image.height = image.m_data.Height; image.CheckAlpha(); return(image); }
public void DrawWidth(GLEx g, int x, int y) { try { if (drawTexWidth == null) { LImage img = LImage.CreateImage(width, height, true); LGraphics gl = img.GetLGraphics(); for (int i = 0; i < width; i++) { gl.SetColor( (start.GetRed() * (width - i)) / width + (end.GetRed() * i) / width, (start.GetGreen() * (width - i)) / width + (end.GetGreen() * i) / width, (start.GetBlue() * (width - i)) / width + (end.GetBlue() * i) / width, alpha); gl.DrawLine(i, 0, i, height); } drawTexWidth = new LTexture(GLLoader.GetTextureData(img), Loon.Core.Graphics.Opengl.LTexture.Format.SPEED); gl.Dispose(); gl = null; } g.DrawTexture(drawTexWidth, x, y); } catch (Exception) { for (int i = 0; i < width; i++) { g.SetColorValue( (start.GetRed() * (width - i)) / width + (end.GetRed() * i) / width, (start.GetGreen() * (width - i)) / width + (end.GetGreen() * i) / width, (start.GetBlue() * (width - i)) / width + (end.GetBlue() * i) / width, alpha); g.DrawLine(i + x, y, i + x, y + height); } } }
public void DrawHeight(GLEx g, int x, int y) { try { if (drawTexHeight == null) { LImage img = LImage.CreateImage(width, height, true); LGraphics gl = img.GetLGraphics(); for (int i = 0; i < height; i++) { gl.SetColor( (start.GetRed() * (height - i)) / height + (end.GetRed() * i) / height, (start.GetGreen() * (height - i)) / height + (end.GetGreen() * i) / height, (start.GetBlue() * (height - i)) / height + (end.GetBlue() * i) / height, alpha); gl.DrawLine(0, i, width, i); } drawTexHeight = new LTexture(GLLoader.GetTextureData(img), Loon.Core.Graphics.Opengl.LTexture.Format.SPEED); gl.Dispose(); gl = null; } g.DrawTexture(drawTexHeight, x, y); } catch (Exception) { for (int i = 0; i < height; i++) { g.SetColorValue( (start.GetRed() * (height - i)) / height + (end.GetRed() * i) / height, (start.GetGreen() * (height - i)) / height + (end.GetGreen() * i) / height, (start.GetBlue() * (height - i)) / height + (end.GetBlue() * i) / height, alpha); g.DrawLine(x, i + y, x + width, i + y); } } }
public void DrawHeight(LGraphics g, int x, int y) { try { if (drawImgHeight == null) { drawImgHeight = LImage.CreateImage(width, height, true); LGraphics gl = drawImgHeight.GetLGraphics(); for (int i = 0; i < height; i++) { gl.SetColor( (start.GetRed() * (height - i)) / height + (end.GetRed() * i) / height, (start.GetGreen() * (height - i)) / height + (end.GetGreen() * i) / height, (start.GetBlue() * (height - i)) / height + (end.GetBlue() * i) / height, alpha); gl.DrawLine(0, i, width, i); } gl.Dispose(); gl = null; } g.DrawImage(drawImgHeight, x, y); } catch (Exception) { for (int i = 0; i < height; i++) { g.SetColor( (start.GetRed() * (height - i)) / height + (end.GetRed() * i) / height, (start.GetGreen() * (height - i)) / height + (end.GetGreen() * i) / height, (start.GetBlue() * (height - i)) / height + (end.GetBlue() * i) / height, alpha); g.DrawLine(x, i + y, x + width, i + y); } } }
public static LImage CreateImage(int width, int height, bool hasAlpha) { LImage image = new LImage(); image.hasAlpha = hasAlpha; image.width = width; image.height = height; int size = width * height; Color[] pixels = new Color[size]; if (!hasAlpha) { for (int i = 0; i < size; i++) { pixels[i] = Color.Black; } } Texture2D texture = new Texture2D(GL.device, width, height); texture.SetData <Color>(pixels); image.m_data = texture; return(image); }
public void DrawWidth(LGraphics g, int x, int y) { try { if (drawImgWidth == null) { drawImgWidth = LImage.CreateImage(width, height, true); LGraphics gl = drawImgWidth.GetLGraphics(); for (int i = 0; i < width; i++) { gl.SetColor( (start.GetRed() * (width - i)) / width + (end.GetRed() * i) / width, (start.GetGreen() * (width - i)) / width + (end.GetGreen() * i) / width, (start.GetBlue() * (width - i)) / width + (end.GetBlue() * i) / width, alpha); gl.DrawLine(i, 0, i, height); } gl.Dispose(); gl = null; } g.DrawImage(drawImgWidth, x, y); } catch (Exception) { for (int i = 0; i < width; i++) { g.SetColor( (start.GetRed() * (width - i)) / width + (end.GetRed() * i) / width, (start.GetGreen() * (width - i)) / width + (end.GetGreen() * i) / width, (start.GetBlue() * (width - i)) / width + (end.GetBlue() * i) / width, alpha); g.DrawLine(i + x, y, i + x, y + height); } } }
internal static LImage NewImage(Texture2D tex2d) { int size = tex2d.Width * tex2d.Height; Color[] pixels = new Color[size]; tex2d.GetData<Color>(pixels); LImage image = new LImage(); Texture2D newTex2d = new Texture2D(GL.device, tex2d.Width, tex2d.Height); newTex2d.SetData<Color>(pixels); image.m_data = newTex2d; image.width = image.m_data.Width; image.height = image.m_data.Height; image.CheckAlpha(); return image; }
public LImage Clone() { LImage image = new LImage(); image.width = width; image.height = height; image.hasAlpha = hasAlpha; image.m_data = m_data; image.fileName = fileName; image.isExt = isExt; return image; }
public static LImage CreateImage(InputStream ins) { LImage image = null; try { image = new LImage(); image.m_data = Texture2D.FromStream(GL.device, ins); image.width = image.m_data.Width; image.height = image.m_data.Height; image.isExt = true; image.CheckAlpha(); } catch (Exception ex) { Loon.Utils.Debug.Log.Exception(ex); } finally { if (ins != null) { try { ins.Close(); ins = null; } catch (Exception) { } } } return image; }
public static LImage CreateImage(int width, int height, bool hasAlpha) { LImage image = new LImage(); image.hasAlpha = hasAlpha; image.width = width; image.height = height; int size = width * height; Color[] pixels = new Color[size]; if (!hasAlpha) { for (int i = 0; i < size; i++) { pixels[i] = Color.Black; } } Texture2D texture = new Texture2D(GL.device, width, height); texture.SetData<Color>(pixels); image.m_data = texture; return image; }
public static LImage CreateImage(Color[] pixels, int width, int height, bool hasAlpha) { LImage image = new LImage(); image.hasAlpha = hasAlpha; image.width = width; image.height = height; int size = width * height; Texture2D texture = new Texture2D(GL.device, width, height); texture.SetData<Color>(pixels); image.m_data = texture; return image; }
public static LImage CreateImage(LImage image, int x, int y, int width, int height, int transform) { LImage result = new LImage(); if (transform < 4) { result.m_data = new Texture2D(GL.device, width, height, false, SurfaceFormat.Color); } else { result.m_data = new Texture2D(GL.device, height, width, true, SurfaceFormat.Color); } result.width = image.m_data.Width; result.height = image.m_data.Height; result.CheckAlpha(); return result; }
public int PutTile(int id, LImage img, Attribute attribute) { if (active) { TileMap.Tile tile = new TileMap.Tile(); tile.id = id; tile.imgId = imgPack.PutImage(img); tile.attribute = attribute; CollectionUtils.Add(arrays,tile); dirty = true; return tile.imgId; } else { throw new Exception( "Map is no longer active, you can not add new tiles !"); } }
public PShadowEffect(LImage img) : this(img, 0, 0) { }
public LPixmapData(string resName) : this(LImage.CreateImage(resName)) { }
public static LTexture.Mask CreateMask(LImage image) { if (image == null) { throw new RuntimeException("Image is null !"); } return CreateMask(image.GetIntPixels(), image.GetWidth(), image.GetHeight()); }
public PShadowEffect(LImage img, LImage back, int x, int y) : this(img, back, x, y, img.GetWidth(), img.GetHeight()) { }
public PShadowEffect(LImage img, LImage back, int x, int y, int w, int h) { if (deasilTrans == null || widdershinTrans == null) { deasilTrans = new Color[max_pixel]; for (int i = 0; i < max_pixel; i++) { deasilTrans[i] = new Color(i, i, i); } int count = 0; widdershinTrans = new Color[max_pixel]; for (int i = 0; i < max_pixel; i++) { widdershinTrans[count++] = deasilTrans[i]; } } this.SetLocation(x, y); this.width = w; this.height = h; this.visible = true; LImage temp = null; if (back == null) { this.scaleWidth = width / 2; this.scaleHeight = height / 2; temp = GraphicsUtils.GetResize(img, scaleWidth, scaleHeight); this.image = LImage.CreateImage(scaleWidth, scaleHeight, true); this.finalDrawPixels = temp.GetPixels(); this.nowDrawPixels = (Color[])CollectionUtils.CopyOf(finalDrawPixels); if (temp != null) { temp.Dispose(); temp = null; } } else { this.scaleWidth = width / 2; this.scaleHeight = height / 2; temp = GraphicsUtils.GetResize(img, scaleWidth, scaleHeight); this.image = LImage.CreateImage(scaleWidth, scaleHeight, true); if (back.GetWidth() == scaleWidth && back.GetHeight() == scaleHeight) { this.finalBackgroundPixels = back.GetPixels(); this.backgroundPixels = (Color[])CollectionUtils .CopyOf(finalBackgroundPixels); } else { LImage tmp = GraphicsUtils.GetResize(back, scaleWidth, scaleHeight); this.finalBackgroundPixels = tmp.GetPixels(); if (tmp != null) { tmp.Dispose(); tmp = null; } this.backgroundPixels = (Color[])CollectionUtils .CopyOf(finalBackgroundPixels); } this.finalDrawPixels = temp.GetPixels(); this.nowDrawPixels = (Color[])CollectionUtils.CopyOf(finalDrawPixels); } this.SetBlackToWhite(flag); if (temp != null) { temp.Dispose(); temp = null; } if (img != null) { img.Dispose(); img = null; } if (back != null) { back.Dispose(); back = null; } }
public LPixmapData(LImage pix) : this(pix.GetPixels(), pix.GetWidth(), pix.GetHeight()) { }
public static LTexture GetRMXPloadBuoyage(LImage rmxpImage, int width, int height) { if (lazyImages == null) { lazyImages = new Dictionary<string, LTexture>(10); } string keyName = ("buoyage" + width + "|" + height); LTexture lazy = (LTexture)CollectionUtils.Get(lazyImages, keyName); if (lazy == null) { LImage lazyImage; LImage image, left, right, center, up, down = null; int objWidth = 32; int objHeight = 32; int x1 = 128; int x2 = 160; int y1 = 64; int y2 = 96; int k = 1; try { image = GraphicsUtils.DrawClipImage(rmxpImage, objWidth, objHeight, x1, y1, x2, y2); lazyImage = LImage.CreateImage(width, height, true); LGraphics g = lazyImage.GetLGraphics(); left = GraphicsUtils.DrawClipImage(image, k, height, 0, 0, k, objHeight); right = GraphicsUtils.DrawClipImage(image, k, height, objWidth - k, 0, objWidth, objHeight); center = GraphicsUtils.DrawClipImage(image, width, height, k, k, objWidth - k, objHeight - k); up = GraphicsUtils.DrawClipImage(image, width, k, 0, 0, objWidth, k); down = GraphicsUtils.DrawClipImage(image, width, k, 0, objHeight - k, objWidth, objHeight); g.DrawImage(center, 0, 0); g.DrawImage(left, 0, 0); g.DrawImage(right, width - k, 0); g.DrawImage(up, 0, 0); g.DrawImage(down, 0, height - k); g.Dispose(); lazy = lazyImage.GetTexture(); if (lazyImage != null) { lazyImage.Dispose(); lazyImage = null; } lazyImages.Add(keyName, lazy); } catch { return null; } finally { left = null; right = null; center = null; up = null; down = null; image = null; } } return lazy; }
public void Dispose() { this.isClose = true; this.EndUsePixelThread(); this.finalDrawPixels = null; this.nowDrawPixels = null; if (image != null) { image.Dispose(); image = null; } }
public static LImage CreateImage(int width, int height, SurfaceFormat format) { LImage image = new LImage(); image.m_data = new RenderTarget2D(GL.device, width, height, false, format, DepthFormat.None, 0, RenderTargetUsage.PreserveContents); image.width = image.m_data.Width; image.height = image.m_data.Height; image.CheckAlpha(); return image; }
private static LTexture GetRMXPDialog(LImage rmxpImage, int width, int height, int size, int offset) { if (lazyImages == null) { lazyImages = new Dictionary<string, LTexture>(10); } string keyName = "dialog" + width + "|" + height; LTexture lazy = (LTexture)CollectionUtils.Get(lazyImages, keyName); if (lazy == null) { try { int objWidth = 64; int objHeight = 64; int x1 = 128; int x2 = 192; int y1 = 0; int y2 = 64; int center_size = objHeight - size * 2; LImage lazyImage = null; LImage image = null; LImage messageImage = null; image = GraphicsUtils.DrawClipImage(rmxpImage, objWidth, objHeight, x1, y1, x2, y2); LImage centerTop = GraphicsUtils.DrawClipImage(image, center_size, size, size, 0); LImage centerDown = GraphicsUtils.DrawClipImage(image, center_size, size, size, objHeight - size); LImage leftTop = GraphicsUtils.DrawClipImage(image, size, size, 0, 0); LImage leftCenter = GraphicsUtils.DrawClipImage(image, size, center_size, 0, size); LImage leftDown = GraphicsUtils.DrawClipImage(image, size, size, 0, objHeight - size); LImage rightTop = GraphicsUtils.DrawClipImage(image, size, size, objWidth - size, 0); LImage rightCenter = GraphicsUtils.DrawClipImage(image, size, center_size, objWidth - size, size); LImage rightDown = GraphicsUtils.DrawClipImage(image, size, size, objWidth - size, objHeight - size); lazyImage = centerTop; lazyImage = LImage.CreateImage(width, height, true); LGraphics g = lazyImage.GetLGraphics(); g.SetAlpha(0.5f); messageImage = GraphicsUtils.DrawClipImage(rmxpImage, 128, 128, 0, 0, 128, 128); messageImage = GraphicsUtils.GetResize(messageImage, width - offset, height - offset); messageImage.XNAUpdateAlpha(125); g.DrawImage(messageImage, (lazyImage.Width - messageImage.Width) / 2 + 1, (lazyImage.Height - messageImage .Height) / 2 + 1); LImage tmp = GraphicsUtils.GetResize(centerTop, width - (size * 2), size); g.DrawImage(tmp, size, 0); if (tmp != null) { tmp.Dispose(); tmp = null; } tmp = GraphicsUtils.GetResize(centerDown, width - (size * 2), size); g.DrawImage(tmp, size, height - size); if (tmp != null) { tmp.Dispose(); tmp = null; } g.DrawImage(leftTop, 0, 0); tmp = GraphicsUtils.GetResize(leftCenter, leftCenter.GetWidth(), width - (size * 2)); g.DrawImage(tmp, 0, size); if (tmp != null) { tmp.Dispose(); tmp = null; } g.DrawImage(leftDown, 0, height - size); int right = width - size; g.DrawImage(rightTop, right, 0); tmp = GraphicsUtils.GetResize(rightCenter, leftCenter .Width, width - (size * 2)); g.DrawImage(tmp, right, size); if (tmp != null) { tmp.Dispose(); tmp = null; } g.DrawImage(rightDown, right, height - size); g.Dispose(); lazy = lazyImage.GetTexture(); lazyImages.Add(keyName, lazy); image.Dispose(); messageImage.Dispose(); centerTop.Dispose(); centerDown.Dispose(); leftTop.Dispose(); leftCenter.Dispose(); leftDown.Dispose(); rightTop.Dispose(); rightCenter.Dispose(); rightDown.Dispose(); image = null; messageImage = null; centerTop = null; centerDown = null; leftTop = null; leftCenter = null; leftDown = null; rightTop = null; rightCenter = null; rightDown = null; } catch(Exception ex) { Loon.Utils.Debugging.Log.Exception(ex); } } return lazy; }
public int PutTile(int id, LImage img) { return PutTile(id, img, null); }
/// <summary> /// 判定指定的两张图片之间是否产生了碰撞 /// </summary> /// /// <param name="src"></param> /// <param name="x1"></param> /// <param name="y1"></param> /// <param name="dest"></param> /// <param name="x2"></param> /// <param name="y2"></param> /// <returns></returns> public bool isPixelCollide(LImage src, float x1, float y1, LImage dest, float x2, float y2) { float width1 = x1 + src.GetWidth() - 1, height1 = y1 + src.GetHeight() - 1, width2 = x2 + dest.GetWidth() - 1, height2 = y2 + dest.GetHeight() - 1; int xstart = (int)Loon.Utils.MathUtils.Max(x1, x2), ystart = (int)Loon.Utils.MathUtils.Max(y1, y2), xend = (int)Loon.Utils.MathUtils.Min(width1, width2), yend = (int)Loon.Utils.MathUtils.Min(height1, height2); int toty = Loon.Utils.MathUtils.Abs(yend - ystart); int totx = Loon.Utils.MathUtils.Abs(xend - xstart); for (int y = 1; y < toty - 1; y++) { int ny = Loon.Utils.MathUtils.Abs(ystart - (int)y1) + y; int ny1 = Loon.Utils.MathUtils.Abs(ystart - (int)y2) + y; for (int x = 1; x < totx - 1; x++) { int nx = Loon.Utils.MathUtils.Abs(xstart - (int)x1) + x; int nx1 = Loon.Utils.MathUtils.Abs(xstart - (int)x2) + x; try { if (((src.GetPixel(nx, ny).PackedValue != LSystem.TRANSPARENT)) && ((dest.GetPixel(nx1, ny1).PackedValue != LSystem.TRANSPARENT))) { return true; } } catch (Exception e) { Loon.Utils.Debugging.Log.Exception(e); } } } return false; }