using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Facade { class Client { public static void HowToUse() { GC.Collect(); byte[] data = Facade.PrintPicture(102802); Form form = new Form(); form.BackgroundImageLayout = ImageLayout.Stretch; form.BackgroundImage = GenerateBitmapImage(data); form.ShowDialog(); } private static Bitmap GenerateBitmapImage(byte[] data) { int size = (int)Math.Sqrt(data.Length); Bitmap bitmap = new Bitmap(size, size, PixelFormat.Format8bppIndexed); BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, bitmap.PixelFormat); try { for (int rowIdx = 0; rowIdx < bitmapData.Height; ++rowIdx) { Marshal.Copy(data, rowIdx * bitmap.Width, bitmapData.Scan0 + rowIdx * bitmapData.Stride, bitmap.Width); } } finally { bitmap.UnlockBits(bitmapData); } return bitmap; } } }