You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.1 KiB

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;
}
}
}