3 #if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
6 using System.Drawing.Imaging;
8 using System.Runtime.InteropServices;
9 using SiliconStudio.Core;
11 namespace SiliconStudio.
Paradox.Graphics
17 partial class StandardImageHelper
19 public unsafe
static Image LoadFromMemory(IntPtr pSource,
int size,
bool makeACopy, GCHandle? handle)
21 using (var memoryStream =
new UnmanagedMemoryStream((byte*)pSource, size))
22 using (var bitmap = (Bitmap)System.Drawing.Image.FromStream(memoryStream))
24 var sourceArea =
new Rectangle(0, 0, bitmap.Width, bitmap.Height);
27 var bitmapData = bitmap.LockBits(sourceArea, ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
28 var image = Image.New2D(bitmap.Width, bitmap.Height, 1, PixelFormat.B8G8R8A8_UNorm, 1, bitmapData.Stride);
33 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES && SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
35 image.Description.Format = PixelFormat.R8G8B8A8_UNorm;
36 CopyMemoryBGRA(image.PixelBuffer[0].DataPointer, bitmapData.Scan0, image.PixelBuffer[0].BufferStride);
38 Utilities.CopyMemory(image.PixelBuffer[0].DataPointer, bitmapData.Scan0, image.PixelBuffer[0].BufferStride);
43 bitmap.UnlockBits(bitmapData);
48 Utilities.FreeMemory(pSource);
56 public static void SaveGifFromMemory(PixelBuffer[] pixelBuffers,
int count, ImageDescription description, Stream imageStream)
58 SaveFromMemory(pixelBuffers, count, description, imageStream, ImageFormat.Gif);
61 public static void SaveTiffFromMemory(PixelBuffer[] pixelBuffers,
int count, ImageDescription description, Stream imageStream)
63 SaveFromMemory(pixelBuffers, count, description, imageStream, ImageFormat.Tiff);
66 public static void SaveBmpFromMemory(PixelBuffer[] pixelBuffers,
int count, ImageDescription description, Stream imageStream)
68 SaveFromMemory(pixelBuffers, count, description, imageStream, ImageFormat.Bmp);
71 public static void SaveJpgFromMemory(PixelBuffer[] pixelBuffers,
int count, ImageDescription description, Stream imageStream)
73 SaveFromMemory(pixelBuffers, count, description, imageStream, ImageFormat.Jpeg);
76 public static void SavePngFromMemory(PixelBuffer[] pixelBuffers,
int count, ImageDescription description, Stream imageStream)
78 SaveFromMemory(pixelBuffers, count, description, imageStream, ImageFormat.Png);
81 public static void SaveWmpFromMemory(PixelBuffer[] pixelBuffers,
int count, ImageDescription description, Stream imageStream)
83 throw new NotImplementedException();
86 private static void SaveFromMemory(PixelBuffer[] pixelBuffers,
int count, ImageDescription description, Stream imageStream, ImageFormat imageFormat)
88 using (var bitmap =
new Bitmap(description.Width, description.Height))
90 var sourceArea =
new Rectangle(0, 0, bitmap.Width, bitmap.Height);
93 var bitmapData = bitmap.LockBits(sourceArea, ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
98 if (description.Format ==
PixelFormat.R8G8B8A8_UNorm)
99 CopyMemoryBGRA(bitmapData.Scan0, pixelBuffers[0].DataPointer, pixelBuffers[0].BufferStride);
100 else if (description.Format ==
PixelFormat.B8G8R8A8_UNorm)
101 Utilities.CopyMemory(bitmapData.Scan0, pixelBuffers[0].DataPointer, pixelBuffers[0].BufferStride);
103 throw new NotSupportedException();
107 bitmap.UnlockBits(bitmapData);
111 bitmap.Save(imageStream, imageFormat);
System.Windows.Shapes.Rectangle Rectangle
_In_ size_t _In_ size_t size
PixelFormat
Defines various types of pixel formats.