Exemple #1
0
        public static Texture2D BitmapToTexture(GraphicsDevice device, Gdi.Bitmap bitmap)
        {
            MemoryStream ms = new MemoryStream();
            bitmap.Save(ms, ImageFormat.Png); // Save the bitmap to memory
            bitmap.Dispose(); // Dispose the bitmap object

            Texture2D tex = Texture2D.FromStream(device, ms); // Load the texture from the bitmap in memory
            ms.Close(); // Close the memorystream
            ms.Dispose(); // Dispose the memorystream
            return tex; // return the texture
        }
 public Gdi.Image resize(int newWidth, int newHeight, Gdi.Image imgToResize)
 {
     Gdi.Bitmap b = new Gdi.Bitmap( newWidth, newHeight);
     Gdi.Graphics g = Gdi.Graphics.FromImage((Gdi.Image)b);
     g.InterpolationMode = InterpolationMode.HighQualityBicubic;
     g.DrawImage(imgToResize, 0, 0, newWidth, newHeight);
     g.Dispose();
     imgToResize.Dispose();
     return (Gdi.Image)b;
 }