當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。