public static LTexture CreateShadowTexture(LTexture texture, float alpha, float scale, float angle) { int width = texture.Width; int height = texture.Height; LPixmap image = new LPixmap(texture); int centerX = width / 2; int centerY = height / 2; int offsetX = (int)((width - image.Width) / 2); int offsetY = (int)((height - image.Height) / 2); Loon.Core.Geom.Matrix.Transform2i t = new Loon.Core.Geom.Matrix.Transform2i(); t.Rotate(angle, centerX, centerY); t.Zoom(scale, centerX, centerY); LPixmap shadowProcess = new LPixmap(width, height, image.IsAlpha()); shadowProcess.DrawPixmap(image, offsetX, offsetY); shadowProcess.Transparency(); shadowProcess.Mul(255, 0, 0, 0); shadowProcess.Mul((int)(alpha * 255), 255, 255, 255); shadowProcess.Convolve(LPixmap.GaussianBlurKernel()); shadowProcess.Transform(t); if (image != null) { image.Dispose(); image = null; } return(shadowProcess.Texture); }
public static LTexture CreateShadowTexture(LTexture texture, float alpha, float scale, float angle) { int width = texture.Width; int height = texture.Height; LPixmap image = new LPixmap(texture); int centerX = width / 2; int centerY = height / 2; int offsetX = (int)((width - image.Width) / 2); int offsetY = (int)((height - image.Height) / 2); Loon.Core.Geom.Matrix.Transform2i t = new Loon.Core.Geom.Matrix.Transform2i(); t.Rotate(angle, centerX, centerY); t.Zoom(scale, centerX, centerY); LPixmap shadowProcess = new LPixmap(width, height, image.IsAlpha()); shadowProcess.DrawPixmap(image, offsetX, offsetY); shadowProcess.Transparency(); shadowProcess.Mul(255, 0, 0, 0); shadowProcess.Mul((int)(alpha * 255), 255, 255, 255); shadowProcess.Convolve(LPixmap.GaussianBlurKernel()); shadowProcess.Transform(t); if (image != null) { image.Dispose(); image = null; } return shadowProcess.Texture; }
public static LPixmap GetResize(LPixmap image, int w, int h) { if (image == null) { return(null); } if (image.Width == w && image.Height == h) { return(image); } LPixmap result = new LPixmap(w, h, image.IsAlpha()); result.DrawPixmap(image, 0, 0, w, h, 0, 0, image.GetWidth(), image.GetHeight()); return(result); }