예제 #1
0
 private void SaveAsImage(ImageFormat outputFormat, Stream stream, int width, int height)
 {
     byte[] numArray = new byte[width * height * GraphicsExtensions.Size(this.Format)];
     this.GetData <byte>(numArray);
     using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
     {
         BitmapData bitmapdata = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, bitmap.PixelFormat);
         Marshal.Copy(numArray, 0, bitmapdata.Scan0, numArray.Length);
         bitmap.UnlockBits(bitmapdata);
         ImageEx.RGBToBGR((Image)bitmap);
         bitmap.Save(stream, outputFormat);
     }
 }
예제 #2
0
 public static Texture2D FromStream(GraphicsDevice graphicsDevice, Stream stream)
 {
     using (System.Drawing.Bitmap bitmap = (System.Drawing.Bitmap)Image.FromStream(stream))
     {
         ImageEx.RGBToBGR((Image)bitmap);
         byte[]     numArray   = new byte[bitmap.Width * bitmap.Height * 4];
         BitmapData bitmapdata = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         if (bitmapdata.Stride != bitmap.Width * 4)
         {
             throw new NotImplementedException();
         }
         Marshal.Copy(bitmapdata.Scan0, numArray, 0, numArray.Length);
         bitmap.UnlockBits(bitmapdata);
         Texture2D texture2D = new Texture2D(graphicsDevice, bitmap.Width, bitmap.Height);
         texture2D.SetData <byte>(numArray);
         return(texture2D);
     }
 }