public static Texture2D CreateTexture(this TextureResource self, GraphicsDevice device) { Texture2D texture = new Texture2D(device, self.Width, self.Height, false, SurfaceFormat.Color); texture.SetData(self.RawData); return(texture); }
public static TextureResource CreateTextureResource(Texture2D texture) { if (texture == null) throw new ArgumentNullException("texture"); if (texture.Format != SurfaceFormat.Color) throw new ArgumentException("texture must be in Color format"); TextureResource tex = new TextureResource(texture.Width, texture.Height); texture.GetData(tex.RawData); return tex; }
public static TextureResource CreateTextureResource(Texture2D texture) { if (texture == null) { throw new ArgumentNullException("texture"); } if (texture.Format != SurfaceFormat.Color) { throw new ArgumentException("texture must be in Color format"); } TextureResource tex = new TextureResource(texture.Width, texture.Height); texture.GetData(tex.RawData); return(tex); }
public static TextureResource CreateTextureResource(Bitmap image) { if (image == null) throw new ArgumentNullException("image"); TextureResource tex = new TextureResource(image.Width, image.Height); if (image.PixelFormat != PixelFormat.Format32bppArgb) { using (Bitmap compatImage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppArgb)) { compatImage.SetResolution(image.HorizontalResolution, image.VerticalResolution); using (Graphics g = Graphics.FromImage(compatImage)) { g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; g.DrawImage(image, new Point(0, 0)); } Rectangle rect = new Rectangle(0, 0, compatImage.Width, compatImage.Height); BitmapData bmpData = compatImage.LockBits(rect, ImageLockMode.ReadOnly, compatImage.PixelFormat); IntPtr ptr = bmpData.Scan0; System.Runtime.InteropServices.Marshal.Copy(ptr, tex.RawData, 0, tex.RawData.Length); compatImage.UnlockBits(bmpData); } } else { Rectangle rect = new Rectangle(0, 0, image.Width, image.Height); BitmapData bmpData = image.LockBits(rect, ImageLockMode.ReadOnly, image.PixelFormat); IntPtr ptr = bmpData.Scan0; System.Runtime.InteropServices.Marshal.Copy(ptr, tex.RawData, 0, tex.RawData.Length); image.UnlockBits(bmpData); } tex.Apply(c => { return new TFColor(c.B, c.G, c.R, c.A); }); return tex; }
private Bitmap CreateCenteredBitmap(TextureResource source, int width, int height) { using (Bitmap tmp = source.CreateBitmap()) { return CreateCenteredBitmap(tmp, width, height); } }
public static Bitmap CreateCenteredBitmap(TextureResource source, int width, int height) { using (Bitmap tmp = source.CreateBitmap()) { return(CreateCenteredBitmap(tmp, width, height)); } }