Ejemplo n.º 1
0
        private static string GetErrorMessage(int errorCode)
        {
            StringBuilder sb = new StringBuilder(errorMessagLength);

            ScreenshotInterop.SSFormatError(errorCode, sb);
            return(sb.ToString());
        }
Ejemplo n.º 2
0
 public void Close()
 {
     if (this.IsOpened)
     {
         int hr = ScreenshotInterop.SSClose(this.pScreenshot);
         this.pScreenshot = IntPtr.Zero;
     }
 }
Ejemplo n.º 3
0
        public void Open(Bitmap bitmap)
        {
            this.Close();
            Size size = bitmap.Size;
            int  bpp  = Bitmap.GetPixelFormatSize(bitmap.PixelFormat);
            int  hr   = ScreenshotInterop.SSOpen(size.Width, size.Height, bpp, ref this.pScreenshot);

            if (hr != 0)
            {
                throw new ScreenException(hr,
                                          string.Format("SSOpen failed: {0} (error code = 0x{1:X8}).", GetErrorMessage(hr), hr));
            }
        }
Ejemplo n.º 4
0
        public void Render(RenderingContext context)
        {
            if (!this.IsOpened)
            {
                throw new InvalidOperationException();
            }
            Bitmap     bitmap      = context.Bitmap;
            Rectangle  rectangle   = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
            Rectangle  trackBounds = context.Bounds;
            BitmapData bitmapData  = bitmap.LockBits(rectangle, ImageLockMode.WriteOnly, bitmap.PixelFormat);

            try {
                int hr = ScreenshotInterop.SSTake(this.pScreenshot, trackBounds.X, trackBounds.Y, bitmapData.Scan0);
                if (hr != 0)
                {
                    throw new ScreenException(hr, string.Format("Screenshot.Take failed: {0} (error code = 0x{1:X8}).",
                                                                GetErrorMessage(hr), hr));
                }
            }
            finally {
                bitmap.UnlockBits(bitmapData);
            }
        }
Ejemplo n.º 5
0
        public void Render(RenderingContext context)
        {
            Bitmap    bitmap = context.Bitmap;
            Rectangle bounds = context.Bounds;

            if (this.highlight)
            {
                // Render highlight
                Point position = this.cursorPos;
                Point location = bounds.Location;
                position.Offset(-location.X, -location.Y);
                Rectangle highlightBounds = new Rectangle(
                    position.X - this.radious,
                    position.Y - this.radious,
                    this.radious * 2,
                    this.radious * 2
                    );
                Color transparentColor = Color.FromArgb(highlightAlpha, this.color.R, this.color.G, this.color.B);
                using (SolidBrush brush = new SolidBrush(transparentColor)) {
                    context.Graphics.FillEllipse(brush, highlightBounds);
                }
            }
            // Render cursor
            Rectangle  rectangle  = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
            BitmapData bitmapData = bitmap.LockBits(rectangle, ImageLockMode.ReadWrite, bitmap.PixelFormat);

            try {
                int bpp = Bitmap.GetPixelFormatSize(bitmap.PixelFormat);
                int hr  = ScreenshotInterop.SSDrawCursor(bitmapData.Scan0, this.cursorPos.X, this.cursorPos.Y, bounds.X,
                                                         bounds.Y, bitmap.Width, bitmap.Height, bpp);
                // CHECK hr?
            }
            finally {
                bitmap.UnlockBits(bitmapData);
            }
        }