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         }
  • 相关阅读:
    新浪微博 js 解密
    新浪微博、qq rsa密码加密c#实现
    C#版本的discuz authcode函数
    搬地方了,在github弄了个新博客
    python 发送邮件
    通用网页广告监测,ADBlock plus算法的C#实现。
    58同城登录 c#,非直接操作js
    python模块之smtplib: 用python发送SSL/TLS安全邮件
    Python少打字小技巧
    python模块之poplib: 用pop3收取邮件
  • 原文地址:https://www.cnblogs.com/fhmsha/p/1584843.html
Copyright © 2011-2022 走看看