当前位置: 首页>>代码示例>>C#>>正文


C# GraphicsDevice.GetBackBufferData方法代码示例

本文整理汇总了C#中GraphicsDevice.GetBackBufferData方法的典型用法代码示例。如果您正苦于以下问题:C# GraphicsDevice.GetBackBufferData方法的具体用法?C# GraphicsDevice.GetBackBufferData怎么用?C# GraphicsDevice.GetBackBufferData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GraphicsDevice的用法示例。


在下文中一共展示了GraphicsDevice.GetBackBufferData方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TakeScreenShot

        public static void TakeScreenShot(GraphicsDevice device, Keys theKey)
        {
            currentState = Keyboard.GetState();

            if (currentState.IsKeyDown(theKey) && preState.IsKeyUp(theKey))
            {
                byte[] screenData;

                screenData = new byte[device.PresentationParameters.BackBufferWidth * device.PresentationParameters.BackBufferHeight * 4];

                device.GetBackBufferData<byte>(screenData);

                Texture2D Screenshot = new Texture2D(device, device.PresentationParameters.BackBufferWidth, device.PresentationParameters.BackBufferHeight, false, device.PresentationParameters.BackBufferFormat);

                Screenshot.SetData<byte>(screenData);

                string name = "Screenshot_" + counter + ".jpeg";
                while (File.Exists(name))
                {
                    counter += 1;
                    name = "Screenshot_" + counter + ".jpeg";

                }

                Stream stream = new FileStream(name, FileMode.Create);

                Screenshot.SaveAsJpeg(stream, Screenshot.Width, Screenshot.Height);

                stream.Close();

                Screenshot.Dispose();
            }

            preState = currentState;
        }
开发者ID:JeoffreyW,项目名称:2dShooter,代码行数:35,代码来源:GameUtilities.cs

示例2: Screenshot

        public static void Screenshot(GraphicsDevice device)
        {
            byte[] screenData;

            screenData = new byte[device.PresentationParameters.BackBufferWidth * device.PresentationParameters.BackBufferHeight * 4];

            device.GetBackBufferData<byte>(screenData);

            Texture2D t2d = new Texture2D(device, device.PresentationParameters.BackBufferWidth, device.PresentationParameters.BackBufferHeight, false, device.PresentationParameters.BackBufferFormat);

            t2d.SetData<byte>(screenData);

            int i = 0;
            string name = "ScreenShot" + i.ToString() + ".png";
            while (File.Exists(name))
            {
                i += 1;
                name = "ScreenShot" + i.ToString() + ".png";

            }

            Stream st = new FileStream(name, FileMode.Create);

            t2d.SaveAsPng(st, t2d.Width, t2d.Height);

            st.Close();

            t2d.Dispose();
        }
开发者ID:plhearn,项目名称:pet,代码行数:29,代码来源:RolePlayingGame.cs

示例3: Capture

        /// <summary>
        /// Stores the current contents of the back buffer as a .PNG file.
        /// </summary>
        /// <param name="inGraphicsDevice">GraphicsDevice to grab the back buffer data from.</param>
        /// <param name="inFilename">String containing the name of the file to save.</param>
        /// <returns>True if the file is saved successfully, otherwise false.</returns>
        public static bool Capture(GraphicsDevice inGraphicsDevice,
                                   String inFilename, ScreenCaptureType inCaptureExtension)
        {
            if (inCaptureExtension == ScreenCaptureType.UseJPEG) { inFilename = inFilename + ".jpg"; }
            if (inCaptureExtension == ScreenCaptureType.UsePNG) { inFilename = inFilename + ".png"; }

            // Store the current BackBuffer data in a new array of Color values. This
            // will take what is currently on the BackBuffer; everything current being
            // drawn to the screen.
            Color[] colorData = new Color[inGraphicsDevice.Viewport.Width *
                                          inGraphicsDevice.Viewport.Height];
            inGraphicsDevice.GetBackBufferData<Color>(colorData);

            // Next set the colors into a Texture, ready for saving.
            Texture2D backBufferTexture = new Texture2D(inGraphicsDevice,
                                                        inGraphicsDevice.Viewport.Width,
                                                        inGraphicsDevice.Viewport.Height);
            backBufferTexture.SetData<Color>(colorData, 0, colorData.Length);

            // Create the file after checking whether it exists. This requires a means
            // of altering the intended filename so that it cannot overwrite an existing
            // screen-capture, for instance suffixing an incremental digit onto the file
            // name, but this would have to be saved to avoid overwritten files when the
            // game crashes and the count is lost.
            if (!File.Exists(inFilename))
            {
                using (FileStream fileStream = File.Create(inFilename))
                {
                    // The choice passed in as the 3rd parameter just exists for the sake
                    // of providing options. If one is clearly advantageous to the other
                    // I'll hard-code it to use that instead. But, for now, we allow the
                    // choice between JPEG and PNG. PNG files have transparency.
                    switch (inCaptureExtension)
                    {
                        case ScreenCaptureType.UseJPEG:
                            backBufferTexture.SaveAsJpeg(fileStream,
                                                         inGraphicsDevice.Viewport.Width,
                                                         inGraphicsDevice.Viewport.Height);
                            break;
                        case ScreenCaptureType.UsePNG:
                            backBufferTexture.SaveAsPng(fileStream,
                                                        inGraphicsDevice.Viewport.Width,
                                                        inGraphicsDevice.Viewport.Height);
                            break;
                    }

                    fileStream.Flush();
                }

                return true;
            }

            return false;
        }
开发者ID:BaronVonTeapot,项目名称:Basic,代码行数:60,代码来源:ScreenCapture.cs

示例4: PostProcess

        public void PostProcess(GraphicsDevice myDevice)
        {
            if (
                ResolvedTexture.Width != myDevice.Viewport.Width ||
                ResolvedTexture.Height != myDevice.Viewport.Height ||
                ResolvedTexture.Format != myDevice.DisplayMode.Format
                ) {
                LoadResolveTarget(myDevice);
            }

            myDevice.GetBackBufferData(data);
            ResolvedTexture.SetData(data);
            myDevice.Textures[0] = ResolvedTexture;

            foreach (EffectPass pass in Effect.CurrentTechnique.Passes) {
                pass.Apply();
                myDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, verts, 0, 2);
            }

            HMEffectManager.ScreenTexture = ResolvedTexture;
        }
开发者ID:mikeschuld,项目名称:HMEngineXNA,代码行数:21,代码来源:HMPostProcessor.cs

示例5: CaptureJpeg

        public static bool CaptureJpeg(GraphicsDevice inGraphicsDevice, String inFilename)
        {
            inFilename = inFilename + ".jpeg";

            // Store the current BackBuffer data in a new array of Color values. This
            // will take what is currently on the BackBuffer; everything current being
            // drawn to the screen.
            Color[] colorData = new Color[inGraphicsDevice.Viewport.Width *
                                          inGraphicsDevice.Viewport.Height];
            inGraphicsDevice.GetBackBufferData<Color>(colorData);

            // Next set the colors into a Texture, ready for saving.
            Texture2D backBufferTexture = new Texture2D(inGraphicsDevice,
                                                        inGraphicsDevice.Viewport.Width,
                                                        inGraphicsDevice.Viewport.Height);
            backBufferTexture.SetData<Color>(colorData, 0, colorData.Length);

            // Create the file after checking whether it exists. This requires a means
            // of altering the intended filename so that it cannot overwrite an existing
            // screen-capture, for instance suffixing an incremental digit onto the file
            // name, but this would have to be saved to avoid overwritten files when the
            // game crashes and the count is lost.
            if (!File.Exists(inFilename))
            {
                using (FileStream fileStream = File.Create(inFilename))
                {
                    backBufferTexture.SaveAsJpeg(fileStream,
                             inGraphicsDevice.Viewport.Width,
                             inGraphicsDevice.Viewport.Height);

                    fileStream.Flush();
                }

                return true;
            }

            return false;
        }
开发者ID:BaronVonTeapot,项目名称:Basic,代码行数:38,代码来源:ScreenCapture.cs


注:本文中的GraphicsDevice.GetBackBufferData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。