private void Screenshot() { using( ResolveTexture2D screenshot = new ResolveTexture2D( graphics.GraphicsDevice, graphics.GraphicsDevice.PresentationParameters.BackBufferWidth, graphics.GraphicsDevice.PresentationParameters.BackBufferHeight, 1, SurfaceFormat.Color ) ) { GraphicsDevice.ResolveBackBuffer( screenshot ); screenshot.Save( "screenshot.jpg", ImageFileFormat.Jpg ); } }
public void TakeScreenShot(string path) { this.spriteBatch.Begin(); for (int num = 0; num != this.listSprite.Count; num++) { this.listSprite[num].Draw(this.spriteBatch); } this.spriteBatch.End(); ResolveTexture2D resolveTexture2D = new ResolveTexture2D(base.GraphicsDevice, base.GraphicsDevice.PresentationParameters.BackBufferWidth, base.GraphicsDevice.PresentationParameters.BackBufferHeight, 1, SurfaceFormat.Color); base.GraphicsDevice.ResolveBackBuffer(resolveTexture2D); resolveTexture2D.Save(path, ImageFileFormat.Bmp); }
/// <summary> /// Takes a screenshot. /// </summary> /// <param name="filename">The filename.</param> public void TakeScreenshot(string filename) { using (var texture2D = new ResolveTexture2D( mDevice, WIDTH, HEIGHT, 1, SurfaceFormat.Color)) { mDevice.ResolveBackBuffer(texture2D); texture2D.Save(filename, ImageFileFormat.Bmp); } }
private void MakeScreenshot() { try { //NOTE: This doesn't always work on all cards, especially if // desktop mode switches in fullscreen mode! screenshotNum++; // Make sure screenshots directory exists if (Directory.Exists(Directories.ScreenshotsDirectory) == false) Directory.CreateDirectory(Directories.ScreenshotsDirectory); using (ResolveTexture2D dstTexture = new ResolveTexture2D( BaseGame.Device, BaseGame.Width, BaseGame.Height, 1, SurfaceFormat.Color)) { // Get data with help of the resolve method BaseGame.Device.ResolveBackBuffer(dstTexture); dstTexture.Save( ScreenshotNameBuilder(screenshotNum), ImageFileFormat.Jpg); } // using } // try catch (Exception ex) { Log.Write("Failed to save Screenshot: " + ex.ToString()); } // catch (ex) }
/// <summary> /// This old way doesn't work that well. Use the new way. /// </summary> private void checkScreenShotOld() { if( ScreenShot == true ) { // stamp with time and dump to disk. string filename = SPW.path + DateTime.Now.ToString( "MMM_dd_yy__HH_mm_ss_ffffff" ) + ".png"; sw[ "screenshot" ] = new StringItem( "Took screenshot: " + filename + ". Press '5'", 20, graphics.PreferredBackBufferHeight - 40 ); ResolveTexture2D rt = new ResolveTexture2D( GraphicsDevice, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, 1, SurfaceFormat.HalfVector4 ); GraphicsDevice.ResolveBackBuffer( rt ); // Put this on a seperate thread, maybe. rt.Save( filename, ImageFileFormat.Png ); ScreenShot = false; } }
private void TakeScreenshot() { int count = Directory.GetFiles(StorageContainer.TitleLocation+"\\", "ndump*.bmp").Length + 1; string name = "\\ndump" + count.ToString("000") + ".bmp"; GraphicsDevice device = Engine.Device; using (ResolveTexture2D screenshot = new ResolveTexture2D(device, device.PresentationParameters.BackBufferWidth, device.PresentationParameters.BackBufferHeight, 1, SurfaceFormat.Color)) { device.ResolveBackBuffer(screenshot); screenshot.Save(StorageContainer.TitleLocation + name, ImageFileFormat.Bmp); } //MessageRenderer.Instance.PostHeaderMessage("Screenshot dumped to " + name, 3); }
private void UpDownIcon_ValueChanged(object sender, EventArgs e) { try { if (this.IconBmp != null) { this.IconBmp.Dispose(); } PresentationParameters presentationParameters = new PresentationParameters(); presentationParameters.AutoDepthStencilFormat = DepthFormat.Depth24; presentationParameters.BackBufferCount = 1; presentationParameters.BackBufferFormat = SurfaceFormat.Color; presentationParameters.BackBufferHeight = 39; presentationParameters.BackBufferWidth = 39; presentationParameters.EnableAutoDepthStencil = true; presentationParameters.FullScreenRefreshRateInHz = 0; presentationParameters.IsFullScreen = false; presentationParameters.MultiSampleQuality = 0; presentationParameters.MultiSampleType = MultiSampleType.NonMaskable; presentationParameters.PresentationInterval = PresentInterval.One; presentationParameters.PresentOptions = PresentOptions.None; presentationParameters.RenderTargetUsage = RenderTargetUsage.DiscardContents; presentationParameters.SwapEffect = SwapEffect.Discard; GraphicsDevice graphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, DeviceType.Hardware, new Panel().Handle, presentationParameters); this.copiedIcon = new Sprite(graphicsDevice); int index = Convert.ToInt32(this.numericUpDownIcon.Value) / 169; int index2 = Convert.ToInt32(this.numericUpDownIcon.Value) % 169; this.copiedIcon.LoadTextureFromFile(this.ImportedContentFolder + "\\3DDATA\\Control\\RES\\" + this.ImportedTSI.listDDS[index].Path, new Vector2(0f, 0f), new Microsoft.Xna.Framework.Rectangle(this.ImportedTSI.listDDS[index].ListDDS_element[index2].X, this.ImportedTSI.listDDS[index].ListDDS_element[index2].Y, this.ImportedTSI.listDDS[index].ListDDS_element[index2].Width, this.ImportedTSI.listDDS[index].ListDDS_element[index2].Height)); graphicsDevice.Clear(Microsoft.Xna.Framework.Graphics.Color.White); SpriteBatch spriteBatch = new SpriteBatch(graphicsDevice); spriteBatch.Begin(SpriteBlendMode.AlphaBlend); spriteBatch.Draw(this.copiedIcon.texture, new Vector2(0f, 0f), new Microsoft.Xna.Framework.Rectangle?(this.copiedIcon.sourceRectangle), Microsoft.Xna.Framework.Graphics.Color.White); spriteBatch.End(); using (ResolveTexture2D resolveTexture2D = new ResolveTexture2D(graphicsDevice, graphicsDevice.PresentationParameters.BackBufferWidth, graphicsDevice.PresentationParameters.BackBufferHeight, 1, SurfaceFormat.Color)) { graphicsDevice.ResolveBackBuffer(resolveTexture2D); resolveTexture2D.Save("Imported Icon.bmp", ImageFileFormat.Bmp); } this.pictureBox.ImageLocation = "Imported Icon.bmp"; this.IconBmp = new Bitmap("Imported Icon.bmp"); this.copiedIcon = new Sprite(this.textureControl.GraphicsDevice); this.copiedIcon.LoadTextureFromFile(this.ImportedContentFolder + "\\3DDATA\\Control\\RES\\" + this.ImportedTSI.listDDS[index].Path, new Vector2(0f, 0f), new Microsoft.Xna.Framework.Rectangle(this.ImportedTSI.listDDS[index].ListDDS_element[index2].X, this.ImportedTSI.listDDS[index].ListDDS_element[index2].Y, this.ImportedTSI.listDDS[index].ListDDS_element[index2].Width + 1, this.ImportedTSI.listDDS[index].ListDDS_element[index2].Height + 1)); } catch { } }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update( GameTime gameTime ) { KeyboardState keyState = Keyboard.GetState(); GamePadState padState = GamePad.GetState(PlayerIndex.One); // Allows the game to exit if ((padState.Buttons.Back == ButtonState.Pressed) || (keyState.IsKeyDown(Keys.Escape))) { this.Exit(); } //Reset if (keyState.IsKeyDown(Keys.R)) { gameResetKeyDown = true; } else if (keyState.IsKeyUp(Keys.R) && gameResetKeyDown) { gameResetKeyDown = false; //Reset The Game Here Reset(); } CheckPauseMenu(keyState, Mouse.GetState()); //Screenie if (keyState.IsKeyDown(Keys.PrintScreen)) { gameScreenieKeyDown = true; } else if (keyState.IsKeyUp(Keys.PrintScreen) && gameScreenieKeyDown) { gameScreenieKeyDown = false; gamePaused = true; ResolveTexture2D screenShot = new ResolveTexture2D(graphics.GraphicsDevice, 400, 600, 0, SurfaceFormat.Vector4); graphics.GraphicsDevice.ResolveBackBuffer(screenShot); //Find A Place TO Save Screenshot :) ulong append = 0; if ( !Directory.Exists("Screenshots") ) { Directory.CreateDirectory("Screenshots"); } while (File.Exists("Screenshots\\underAttackScreen-" + append + ".png")) { append++; } screenShot.Save("Screenshots\\underAttackScreen-" + append + ".png", ImageFileFormat.Png); } if ((gameTime.TotalGameTime.TotalMilliseconds - lastAnimUpdate) > 100) { foreach (GameUnit unit in animations) { if (unit.IsAnimating) { unit.CurrentFrame = unit.CurrentFrame + 1; if (unit.CurrentFrame >= (sprites[unit.SpriteName].FrameCount)) { deadAnims.Add(unit); } } } //Time Updating here too - ONLY when game is running if (!gameOver && !gamePaused) { timePassed++; timeParam.SetValue(timePassed / 20f); } lastAnimUpdate = gameTime.TotalGameTime.TotalMilliseconds; } if (!gameOver && !gamePaused) { //Count time alive timeAlive += gameTime.ElapsedGameTime.TotalSeconds; //Motion Input CheckPlayerInput(keyState); //Move all Units where auto-motion is req. MoveGameUnits(); //Check For A Press And Release To Fire...Make Sure Every Release Is atleast 250 Ms apart if (keyState.IsKeyDown(Keys.Space) && !gameShootKeyDown && ((gameTime.TotalGameTime.TotalMilliseconds - lastShotUpdate) > 200) ) { gameShootKeyDown = true; } else if (keyState.IsKeyUp(Keys.Space) && gameShootKeyDown) { GameUnit bullet = new GameUnit("bullet", playerOne.Position - new Vector2(0, 32), new Vector2(4f, 4f)); bullet.Velocity = new Vector2(0, -2); units.Add(bullet); //Update last shot time lastShotUpdate = gameTime.TotalGameTime.TotalMilliseconds; //Reset Press variable gameShootKeyDown = false; } //Remove Dead Units foreach (GameUnit e in deadBullets) { units.Remove(e); } foreach (GameUnit e in deadUnits) { units.Remove(e); } foreach (GameUnit e in deadAnims) { units.Remove(e); } //Clear already dead units. deadBullets.Clear(); deadUnits.Clear(); deadAnims.Clear(); } base.Update(gameTime); }