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


C# RenderTarget2D.SaveAsJpeg方法代码示例

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


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

示例1: Draw

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            #region Set up screenshots
            if (isScreenshot)
            {
                Color[] screenData = new Color[GraphicsDevice.PresentationParameters.BackBufferWidth *
                                           GraphicsDevice.PresentationParameters.BackBufferHeight];

                screenShot = new RenderTarget2D(GraphicsDevice,
                    GraphicsDevice.PresentationParameters.BackBufferWidth,
                    GraphicsDevice.PresentationParameters.BackBufferHeight);

                GraphicsDevice.SetRenderTarget(screenShot);

                map.Draw(spriteBatch);
                base.Draw(gameTime);

                GraphicsDevice.SetRenderTarget(null);

                //save to disk
                string fileName = DateTime.Now.ToString();
                fileName = fileName.Replace('/', '-');
                fileName = fileName.Replace(':', '-');

                Stream stream = File.OpenWrite("\\Screens\\" + fileName + ".jpg");
                screenShot.SaveAsJpeg(stream,
                                        1280,
                                        720);
                stream.Dispose();
                screenShot.Dispose();

                //reset the screenshot flag
                isScreenshot = false;
            }
            #endregion

            map.Draw(spriteBatch);
            base.Draw(gameTime);
        }
开发者ID:mrahmani,项目名称:FanmadeV2,代码行数:46,代码来源:Game1.cs

示例2: SaveScreenshot

        public void SaveScreenshot(string filename)
        {
            Color[] screenData = new Color[GraphicsDevice.PresentationParameters.BackBufferWidth * GraphicsDevice.PresentationParameters.BackBufferHeight];

            RenderTarget2D screenShot = new RenderTarget2D(GraphicsDevice, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);

            GraphicsDevice.SetRenderTarget(screenShot);

            Draw(new GameTime());

            GraphicsDevice.SetRenderTarget(null);

            int index = 0;
            string name = string.Concat(filename, "_", index, ".jpg");
            while (File.Exists(name)) {
                index++;
                name = string.Concat(filename, "_", index, ".jpg");
            }

            using (FileStream stream = new FileStream(name, FileMode.CreateNew)) {
                screenShot.SaveAsJpeg(stream, screenShot.Width, screenShot.Height);
                screenShot.Dispose();
            }
        }
开发者ID:dotKokott,项目名称:MathFighter,代码行数:24,代码来源:MainGame.cs

示例3: SaveData

        /// <summary>
        /// Saves all the undoRedoRenderTargets to disk and the imageStateData
        /// </summary>
        /// <param name='imageStateData'>Image state data.</param>
        /// <param name='masterImageRenderTarget' Master image render target/>
        /// <param name='undoRedoRenderTargets'>Sequence of images representing the undo/redo chain</param>
        /// <param name='bottomMarginToCutOff'>Because the toolbox will always take up some space we will cut off the bottom section (toolbox height)
        /// when saving the master image so that there is no annoying white space at the bottom</param>
        public void SaveData(ImageStateData imageStateData, RenderTarget2D masterImageRenderTarget, RenderTarget2D[] undoRedoRenderTargets, int bottomMarginToCutOff)
        {
            this.SaveImageStateData(this.filenameResolver.MasterImageInfoFilename, imageStateData);

            int end = imageStateData.FirstSavePoint == 0 ? imageStateData.LastSavePoint : imageStateData.MaxUndoRedoCount - 1;

            for (int count = 0; count <= end; count++)
            {
                var renderTarget = undoRedoRenderTargets[count];

                // Save the render target to disk
                renderTarget.SaveAsPng(
                    this.filenameResolver.ImageSavePointFilename(count),
                    renderTarget.Width,
                    renderTarget.Height);

                // copy the working canvas recorder file into the master folder.
                var masterCanvasRecorderFile = this.filenameResolver.MasterCanvasRecorderFilename(count);

                if (File.Exists(masterCanvasRecorderFile))
                {
                    File.Delete(masterCanvasRecorderFile);
                }

                File.Move(this.filenameResolver.WorkingCanvasRecorderFilename(count), masterCanvasRecorderFile);
            }

            // Save the Master image as a JPG as it has no alpha channel - which is ideal for displaying on the home
            // home screen where we don't want the background image showing through
            masterImageRenderTarget.SaveAsJpeg(
                this.filenameResolver.MasterImageFilename,
                masterImageRenderTarget.Width,
                masterImageRenderTarget.Height - bottomMarginToCutOff);

            File.Delete(this.filenameResolver.WorkingImageInfoFilename);
        }
开发者ID:RandolphBurt,项目名称:MonoGame-iOS-SimplePaint,代码行数:44,代码来源:PictureIOManager.cs


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