public int Fill(Context context)
 {
     Init(context);
     Process(context.x, context.y);
     bitmap = new Bitmap(bitmapWidth, bitmapHeight, bitmapStride, PixelFormat.Format32bppArgb, bitPtr);
     context.bitmap = this.bitmap;
     return 1;
 }
示例#2
0
 public static Context getInstance()
 {
     if (instance == null)
     {
         instance = new Context();
     }
     return instance;
 }
        void Init(Context context)
        {
            startColor = new byte[] { context.colorStart.B, context.colorStart.G, context.colorStart.R };
            byteFillColor = new byte[] { context.colorFill.B, context.colorFill.G, context.colorFill.R };
            byteBoundColor = new byte[] { context.colorBoundary.B, context.colorBoundary.G, context.colorBoundary.R };
            bitmapWidth = context.img.Width;
            bitmapHeight = context.img.Height;

            pixelFormatSize = Image.GetPixelFormatSize(PixelFormat.Format32bppArgb) / 8;
            bitmapStride = bitmapWidth * pixelFormatSize;
            padding = (bitmapStride % 4);
            bitmapStride += padding == 0 ? 0 : 4 - padding;//pad out to multiple of 4
            bitmapPixelFormatSize = pixelFormatSize;

            bits = new byte[bitmapStride * bitmapWidth];
            handle = GCHandle.Alloc(bits, GCHandleType.Pinned);
            bitPtr = Marshal.UnsafeAddrOfPinnedArrayElement(bits, 0);
            bitmap = new Bitmap(bitmapWidth, bitmapHeight, bitmapStride, PixelFormat.Format32bppArgb, bitPtr);
            Graphics g = Graphics.FromImage(bitmap);
            Bitmap bmImg = new Bitmap(context.img);
            g.DrawImageUnscaledAndClipped(bmImg, new Rectangle(0, 0, bitmapWidth, bitmapHeight));
            g.Dispose();
        }