Beispiel #1
0
        private void CaptureThread()
        {
            // leave if not supported
            if (display.DeviceCaps.MaxTextureHeight < Screen.PrimaryScreen.Bounds.Height && display.DeviceCaps.MaxTextureWidth < Screen.PrimaryScreen.Bounds.Width)
            {
                return;
            }

            // destroy previous texture
            if (this.ScreenCapture != null)
            {
                this.ScreenCapture.FreeReference();
                this.ScreenCapture = null;
            }

            // capture
            using (Bitmap MyBg = new Bitmap(SrcRect.Width, SrcRect.Height))
            {
                try
                {
                    // getting from clipboard
                    using (Bitmap screen = (Bitmap)Clipboard.GetDataObject().GetData(typeof(Bitmap)))
                    {
                        // drawing on final file
                        using (Graphics g = Graphics.FromImage((Image)MyBg))
                        {
                            g.DrawImage(screen, new Rectangle(new Point(0, 0), SrcRect.Size), SrcRect.X, SrcRect.Y, SrcRect.Width, SrcRect.Height, System.Drawing.GraphicsUnit.Pixel);
                        }
                    }
                    // creating texture
                    this.ScreenCapture = OrbitTextureLoader.Load(display, MyBg);
                    // validating
                    this.CanDraw = true;
                    // request update
                    if (this.Paint != null)
                    {
                        this.Paint(this, new EventArgs());
                    }
                }
                catch (Exception)
                {
                    // failed somewhere, so can't draw
                    this.CanDraw = false;
                    // delete vestigies
                    if (ScreenCapture != null)
                    {
                        ScreenCapture.FreeReference();
                        ScreenCapture = null;
                    }
                }
                // restoring the old clipboard
                RestoreOldClipboard();
            }
        }
Beispiel #2
0
        //Bitmap b;
        private void CaptureFromBitBlt()
        {
            try
            {
                // creating the bitmap
                using (Bitmap b = new Bitmap(SrcRect.Width, SrcRect.Height))
                {
                    // capturing
                    using (Graphics g = Graphics.FromImage(b))
                    {
                        IntPtr hdcScreen = Win32.GDI.GDIAPI.CreateDC("DISPLAY", null, null, IntPtr.Zero);
                        IntPtr hdcG      = g.GetHdc();

                        Win32.GDI.GDIAPI.BitBlt(hdcG, 0, 0, b.Width, b.Height, hdcScreen, SrcRect.X, SrcRect.Y, Win32.GDI.RasterOperation.SourceCopy);

                        g.ReleaseHdc(hdcG);
                        Win32.GDI.GDIAPI.DeleteDC(hdcScreen);
                    }
                    // destroy previous texture
                    if (this.ScreenCapture != null)
                    {
                        this.ScreenCapture.FreeReference();
                        this.ScreenCapture = null;
                    }

                    // creating texture
                    this.ScreenCapture = OrbitTextureLoader.Load(display, b);
                    // validating
                    this.CanDraw = true;
                    this.Alpha   = 255;
                    // request update
                    if (this.Paint != null)
                    {
                        this.Paint(this, new EventArgs());
                    }
                }
            }
            catch (Exception)
            {
                // failed somewhere, so can't draw
                this.CanDraw = false;
                this.Alpha   = 0;
                // delete vestigies
                if (ScreenCapture != null)
                {
                    ScreenCapture.FreeReference();
                    ScreenCapture = null;
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Sets the Non Transparent background Texture
        /// </summary>
        /// <param name="Path">Path to load the Texture from</param>
        /// <returns>True if succeeded</returns>
        protected bool SetBg(string Path)
        {
            // dispose old background
            DisposeBg();

            try
            {
                // use custom loader to load
                BG = OrbitTextureLoader.Load(display, Path);
                // only loaded if not null
                if (BG != null)
                {
                    // get description and set path properly
                    _BackgroundPath = Path;
                    return(true);
                }
            }
            catch (Exception) {}

            // code will only reach this if failed loading
            _BackgroundPath = "";
            return(false);
        }