コード例 #1
0
        /// <summary>
        /// Creates an image containing pixels read from the screen.  This image does
        /// not include the mouse cursor. </summary>
        /// <param name="screenRect">      Rect to capture in screen coordinates </param>
        /// <returns>  The captured image </returns>
        /// <exception cref="IllegalArgumentException"> if <code>screenRect</code> width and height are not greater than zero </exception>
        /// <exception cref="SecurityException"> if <code>readDisplayPixels</code> permission is not granted </exception>
        /// <seealso cref=     SecurityManager#checkPermission </seealso>
        /// <seealso cref=     AWTPermission </seealso>
        public virtual BufferedImage CreateScreenCapture(Rectangle screenRect)
        {
            lock (this)
            {
                CheckScreenCaptureAllowed();

                CheckValidRect(screenRect);

                BufferedImage  image;
                DataBufferInt  buffer;
                WritableRaster raster;

                if (ScreenCapCM == null)
                {
                    /*
                     * Fix for 4285201
                     * Create a DirectColorModel equivalent to the default RGB ColorModel,
                     * except with no Alpha component.
                     */

                    ScreenCapCM = new DirectColorModel(24, 0x00FF0000, 0x0000FF00, 0x000000FF);
                    /* red mask */
                    /* green mask */
                    /* blue mask */
                }

                // need to sync the toolkit prior to grabbing the pixels since in some
                // cases rendering to the screen may be delayed
                Toolkit.DefaultToolkit.Sync();

                int[] pixels;
                int[] bandmasks = new int[3];

                pixels = Peer.GetRGBPixels(screenRect);
                buffer = new DataBufferInt(pixels, pixels.Length);

                bandmasks[0] = ScreenCapCM.RedMask;
                bandmasks[1] = ScreenCapCM.GreenMask;
                bandmasks[2] = ScreenCapCM.BlueMask;

                raster = Raster.CreatePackedRaster(buffer, screenRect.Width_Renamed, screenRect.Height_Renamed, screenRect.Width_Renamed, bandmasks, null);
                SunWritableRaster.makeTrackable(buffer);

                image = new BufferedImage(ScreenCapCM, raster, false, null);

                return(image);
            }
        }
コード例 #2
0
        /// <summary>
        /// Return a Raster containing the colors generated for the graphics
        /// operation. </summary>
        /// <param name="x">,y,w,h The area in device space for which colors are
        /// generated. </param>
        public virtual Raster GetRaster(int x, int y, int w, int h)
        {
            if (OutRas == null || OutRas.Width < w || OutRas.Height < h)
            {
                // If h==1, we will probably get lots of "scanline" rects
                OutRas = MakeRaster((h == 1 ? System.Math.Max(w, MaxWidth) : w), h);
            }
            double X = Mod(XOrg + x * IncXAcross + y * IncXDown, BWidth);
            double Y = Mod(YOrg + x * IncYAcross + y * IncYDown, BHeight);

            SetRaster((int)X, (int)Y, FractAsInt(X), FractAsInt(Y), w, h, BWidth, BHeight, Colincx, Colincxerr, Colincy, Colincyerr, Rowincx, Rowincxerr, Rowincy, Rowincyerr);

            SunWritableRaster.markDirty(OutRas);

            return(OutRas);
        }
コード例 #3
0
ファイル: SplashScreen.cs プロジェクト: ranganathsb/JavaSharp
        /// <summary>
        /// Updates the splash window with current contents of the overlay image.
        /// </summary>
        /// <exception cref="IllegalStateException"> if the overlay image does not exist;
        ///         for example, if {@code createGraphics} has never been called,
        ///         or if the splash screen has already been closed </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void update() throws IllegalStateException
        public void Update()
        {
            BufferedImage image;

            lock (typeof(SplashScreen))
            {
                CheckVisible();
                image = this.Image;
            }
            if (image == null)
            {
                throw new IllegalStateException("no overlay image available");
            }
            DataBuffer buf = image.Raster.DataBuffer;

            if (!(buf is DataBufferInt))
            {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                throw new AssertionError("Overlay image DataBuffer is of invalid type == " + buf.GetType().FullName);
            }
            int numBanks = buf.NumBanks;

            if (numBanks != 1)
            {
                throw new AssertionError("Invalid number of banks ==" + numBanks + " in overlay image DataBuffer");
            }
            if (!(image.SampleModel is SinglePixelPackedSampleModel))
            {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                throw new AssertionError("Overlay image has invalid sample model == " + image.SampleModel.GetType().FullName);
            }
            SinglePixelPackedSampleModel sm = (SinglePixelPackedSampleModel)image.SampleModel;
            int       scanlineStride        = sm.ScanlineStride;
            Rectangle rect = image.Raster.Bounds;

            // Note that we steal the data array here, but just for reading
            // so we do not need to mark the DataBuffer dirty...
            int[] data = SunWritableRaster.stealData((DataBufferInt)buf, 0);
            lock (typeof(SplashScreen))
            {
                CheckVisible();
                _update(SplashPtr, data, rect.x, rect.y, rect.Width_Renamed, rect.Height_Renamed, scanlineStride);
            }
        }