• 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         }
  • 相关阅读:
    [sql]在case语句中不同情况下then的数据的数据类型不一致ORA-00932: inconsistent datatypes: expected NUMBER got CHAR
    环境迁移 小记
    linux下安装oracle遇到的问题
    正向代理与反向代理
    文件夹与SVN脱离关系
    shell 脚本中$$,$#,$?
    在MySQL中单列索引和联合索引的区别
    Java中Map、HashMap、LinkedHashMap、TreeMap的区别
    Error、Exception与RuntimeException的区别
    设计模式--单例模式
  • 原文地址:https://www.cnblogs.com/fhmsha/p/1584843.html
Copyright © 2020-2023  润新知