怎么在C#中利用SDL2实现一个视频播放窗口截图-创新互联
本篇文章给大家分享的是有关怎么在C# 中利用SDL2实现一个视频播放窗口截图,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
创新互联-专业网站定制、快速模板网站建设、高性价比新建网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式新建网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖新建地区。费用合理售后完善,十载实体公司更值得信赖。具体方法如下
////// SDL2截图操作类 /// public unsafe class SDLScreenshot { IntPtr window;// 窗口对象 IntPtr renderer;// 播放窗口的渲染器(来自于已初始化的播放窗口渲染器) public SDLScreenshot(IntPtr window, IntPtr renderer) { this.window = window; this.renderer = renderer; } ////// 保存截图 /// /// /// /// 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); } ////// 加载截图 /// /// /// /// 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实现一个视频播放窗口截图-创新互联
转载源于:http://scgulin.cn/article/pspge.html