diff --git a/ANX.Framework.Content.Pipeline/Graphics/PixelBitmapContent.cs b/ANX.Framework.Content.Pipeline/Graphics/PixelBitmapContent.cs index 1f7c3723..409e7605 100644 --- a/ANX.Framework.Content.Pipeline/Graphics/PixelBitmapContent.cs +++ b/ANX.Framework.Content.Pipeline/Graphics/PixelBitmapContent.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; +using System.IO; #endregion @@ -17,16 +18,18 @@ namespace ANX.Framework.Content.Pipeline.Graphics public class PixelBitmapContent : BitmapContent where T : struct, IEquatable { private T[,] pixels; + private int pixelSize; protected PixelBitmapContent() { - + this.pixelSize = Marshal.SizeOf(typeof(T)); } public PixelBitmapContent(int width, int height) : base(width, height) { pixels = new T[width, height]; + this.pixelSize = Marshal.SizeOf(typeof(T)); } public T GetPixel(int x, int y) @@ -38,14 +41,39 @@ namespace ANX.Framework.Content.Pipeline.Graphics { int rowSize = Marshal.SizeOf(typeof(T)) * base.Width; byte[] array = new byte[rowSize * base.Height]; + + int destinationIndex = 0; for (int i = 0; i < base.Height; i++) { T[] row = GetRow(i); + for (int x = 0; x < row.Length; x++) + { + Array.Copy(GetBytes(row[x]), 0, array, destinationIndex, pixelSize); + destinationIndex += pixelSize; + } } + return array; } + private static byte[] GetBytes(T value) + { + byte[] buffer = new byte[Marshal.SizeOf(typeof(T))]; + + GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); + try + { + Marshal.StructureToPtr(value, handle.AddrOfPinnedObject(), false); + } + finally + { + handle.Free(); + } + + return buffer; + } + public T[] GetRow(int y) { T[] row = new T[Width]; diff --git a/Samples/WindowsGame/WindowsGame_WindowsMetro.csproj b/Samples/WindowsGame/WindowsGame_WindowsMetro.csproj index 023df114..8e2cb7f7 100644 --- a/Samples/WindowsGame/WindowsGame_WindowsMetro.csproj +++ b/Samples/WindowsGame/WindowsGame_WindowsMetro.csproj @@ -67,7 +67,9 @@ - + + Form + AddInSelector.cs