怎么在C#中利用SDL2实现一个视频播放窗口截图-创新互联

本篇文章给大家分享的是有关怎么在C# 中利用SDL2实现一个视频播放窗口截图,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

创新互联-专业网站定制、快速模板网站建设、高性价比新建网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式新建网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖新建地区。费用合理售后完善,十载实体公司更值得信赖。

具体方法如下

 /// <summary>
 /// SDL2截图操作类
 /// </summary>
 public unsafe class SDLScreenshot
 {
  IntPtr window;// 窗口对象
  IntPtr renderer;// 播放窗口的渲染器(来自于已初始化的播放窗口渲染器) 
  public SDLScreenshot(IntPtr window, IntPtr renderer)
  {
   this.window = window;
   this.renderer = renderer;
  } 
  /// <summary>
  /// 保存截图
  /// </summary>
  /// <param name="width"></param>
  /// <param name="height"></param>
  /// <param name="path"></param>
  public void SaveBMP(int width, int height,string path)
  {
   // 判断渲染器是否初始化
   if (renderer == IntPtr.Zero)
   {
    Console.WriteLine("renderer is null ,please call Init() method.");
    return;
   }
   uint Rmask=0x00FF0000, Gmask = 0x0000FF00, Bmask = 0x000000FF, Amask = 0x00000000;
   // 获取图像数据
   SDL.SDL_Surface* surface= (SDL.SDL_Surface*)SDL.SDL_CreateRGBSurface(0, width, height, 32, Rmask, Gmask, Bmask, Amask);
   //设置纹理的数据
   SDL.SDL_Rect destrect;
   destrect.x = 0;
   destrect.y = 0;
   destrect.w = width;
   destrect.h = height; 
 
   // 读取并渲染图像数据
   SDL.SDL_RenderReadPixels(renderer, ref destrect, SDL.SDL_PIXELFORMAT_ARGB8888, surface->pixels, surface->pitch); 
 
   //保存图片
   int i = SDL.SDL_SaveBMP((IntPtr)surface, path);
   if (i != 0)
   {
    Console.WriteLine("screenshot failed." + SDL.SDL_GetError());
   } 
 
   SDL.SDL_FreeSurface((IntPtr)surface);
   //SDL.SDL_RenderClear(renderer);
   //SDL.SDL_DestroyRenderer(renderer); 
  } 
 
  /// <summary>
  /// 加载截图
  /// </summary>
  /// <param name="width"></param>
  /// <param name="height"></param>
  /// <param name="path"></param>
  public void LoadBMP(int width, int height, string path)
  {
   // 判断渲染器是否初始化
   if (renderer == IntPtr.Zero)
   {
    Console.WriteLine("renderer is null ,please call Init() method.");
    return;
   }
   // 加载图片
   IntPtr surface = SDL.SDL_LoadBMP(path);
   if (surface == IntPtr.Zero)
   {
    Console.WriteLine("load bmp failed." + SDL.SDL_GetError());
    return;
   }
   IntPtr texture = SDL.SDL_CreateTextureFromSurface(renderer, surface);
   if (texture == IntPtr.Zero)
   {
    Console.WriteLine("create texture failed." + SDL.SDL_GetError());
    return;
   }
   SDL.SDL_FreeSurface(surface); 
 
   //设置纹理的数据
   SDL.SDL_Rect destrect;
   destrect.x = 0;
   destrect.y = 0;
   destrect.w = width;
   destrect.h = height; 
 
   SDL.SDL_Rect srcrect = destrect; 
 
   //SDL.SDL_RenderClear(renderer);
   SDL.SDL_RenderCopy(renderer, texture, ref srcrect, ref destrect);
   SDL.SDL_RenderPresent(renderer);
 
 
   //SDL.SDL_Delay(20); 
   SDL.SDL_DestroyTexture(texture);
   //SDL.SDL_DestroyRenderer(renderer);
   //SDL.SDL_DestroyWindow(screen);
   //Quit SDL 
   //SDL.SDL_Quit();
  }
 }

分享标题:怎么在C#中利用SDL2实现一个视频播放窗口截图-创新互联
链接URL:https://www.cdcxhl.com/article14/pspge.html

成都网站建设公司_创新互联,为您提供微信公众号外贸网站建设网站策划全网营销推广网站排名移动网站建设

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

网站优化排名