zoukankan      html  css  js  c++  java
  • xna中的截屏操作处理

    游戏中常会用到截图,如果是用默认的截屏键PrintScreen的话,用户又要在另外的地方粘贴才可以。
    这样做的话比较自由:
     1 /// <summary>
     2         /// Saves a screenshot to disk with running number.
     3         /// Does not overwrite existing screenshots.
     4         /// </summary>
     5         public void SaveScreenshot() {
     6             // Find a free name
     7             int number = 0;
     8             string filename = String.Format("screenshot{0:00}.png", number);
     9             while (System.IO.File.Exists(filename)) {
    10                 filename = String.Format("screenshot{0:00}.png"++number);
    11             }
    12 
    13             // Take the screenshot
    14             GraphicsDevice device = graphics.GraphicsDevice;
    15             int w = device.PresentationParameters.BackBufferWidth;
    16             int h = device.PresentationParameters.BackBufferHeight;
    17             using (ResolveTexture2D screenshot = new ResolveTexture2D(device, w, h, 1, SurfaceFormat.Color)) {
    18                 // Grab the screenshot
    19                 device.ResolveBackBuffer(screenshot);
    20 
    21                 // Set the alpha to full
    22                 Color[] data = new Color[screenshot.Width * screenshot.Height];
    23                 screenshot.GetData<Color>(data);
    24                 int pos = 0;
    25                 foreach (Color c in data) {
    26                     data[pos++= new Color(c.R, c.G, c.B, 255);
    27                 }
    28 
    29                 // Write to disk
    30                 screenshot.SetData<Color>(data);
    31                 screenshot.Save(filename, ImageFileFormat.Png);
    32                 screenshot.Dispose();
    33             }
    34         }
  • 相关阅读:
    Typora+PicGo图片上传教程
    创建一个springbootcloud项目
    plugin.xml 解析说明
    Java 元注解 使用示例
    Spring 注解学习 使用示例
    springboot2.2 集成 activity6 请假完整示例
    SpringBoot 过滤器,拦截器初步学习整理(有示例代码)
    mybatis plus mysql 代码生成器 示例demo
    Bootstrap相关方法,事件整理
    网站链接
  • 原文地址:https://www.cnblogs.com/fhmsha/p/1584843.html
Copyright © 2011-2022 走看看