StretchBlt和StretchDIBits
StretchBlt:从源矩形中复制一个位图到目标矩形,必要时按目标设备设置的模式进行图像的拉伸或压缩,如果目标设备是窗口DC,则意味着在窗口绘制位图,大致的使用代码如下:
void DrawImage(HDC hdc, HBITMAP hbm, const RECT target_rect)
{
HDC hdcMemory = ::CreateCompatibleDC(hdc);
HBITMAP old_bmp = (HBITMAP)::SelectObject(hdcMemory, hbm); BITMAP bm = { };
::GetObject(hbm, sizeof(bm), &bm); ::StretchBlt(
hdc, // Target device HDC
target_rect.left, // X sink position
target_rect.top, // Y sink position
target_rect.right - target_rect.left, // Destination width
target_rect.bottom - target_rect.top, // Destination height
hdcMemory, // Source device HDC
, // X source position
, // Y source position
bm.bmWidth, // Source width
bm.bmHeight, // Source height
SRCCOPY); // Simple copy ::SelectObject(hdcMemory, old_bmp);
::DeleteObject(hdcMemory);
}
StretchDIBits:该函数将DIB(设备无关位图)中矩形区域内像素使用的颜色数据拷贝到指定的目标矩形中,如果目标设备是窗口DC,同样意味着在窗口绘制位图,大致的使用代码如下:
void DrawImage(HDC hdc, LPBITMAPINFOHEADER lpbi, void* bits, const RECT target_rect)
{
::StretchDIBits(
hdc, // Target device HDC
target_rect.left, // X sink position
target_rect.top, // Y sink position
target_rect.right - target_rect.left, // Destination width
target_rect.bottom - target_rect.top, // Destination height
, // X source position
, // Adjusted Y source position
lpbi->biWidth, // Source width
abs(lpbi->biHeight), // Source height
bits, // Image data
(LPBITMAPINFO)lpbi, // DIB header
DIB_RGB_COLORS, // Type of palette
SRCCOPY); // Simple image copy
}
简单的讲,StretchBlt操作的是设备相关位图是HBITMAP句柄,StretchDIBits操作的是设备无关位图是内存中的RGB数据。
DirectShow示例代码中的CDrawImage类提供了FastRender和SlowRender两个函数用于渲染视频图像,FastRender用的StretchBlt,SlowRender用的StretchDIBits,其中SlowRender的注释是这样写的:
// This is called when there is a sample ready to be drawn, unfortunately the
// output pin was being rotten and didn't choose our super excellent shared
// memory DIB allocator so we have to do this slow render using boring old GDI
// SetDIBitsToDevice and StretchDIBits. The down side of using these GDI
// functions is that the image data has to be copied across from our address
// space into theirs before going to the screen (although in reality the cost
// is small because all they do is to map the buffer into their address space)
也就是说StretchDIBits比StretchBlt多消耗了从内存地址空间拷贝图像数据到GDI地址空间的时间。实际测试结果在XP和Win7系统下两者效率几乎没有区别,所以可以放心大胆的使用StretchDIBits,毕竟内存数据处理起来要方便的多。
StretchBlt和StretchDIBits的更多相关文章
- Delphi 7中对StretchBlt, StretchDIBits, DrawDibDraw, BitBlt 的性能测试 - 原创
我的天哪,上一篇博文是2年前的事情了.看来又虚度了2年光阴,继续学习... 本文算是副产品,正品是利用FFmpeg从任意视频中生成GIF片段的小程序,等写完了再发.不为别的,只是为了给儿子做动图,且看 ...
- Windows API 函数列表 附帮助手册
所有Windows API函数列表,为了方便查询,也为了大家查找,所以整理一下贡献出来了. 帮助手册:700多个Windows API的函数手册 免费下载 API之网络函数 API之消息函数 API之 ...
- API函数
1. API之网络函数 WNetAddConnection 创建同一个网络资源的永久性连接 WNetAddConnection2 创建同一个网络资源的连接 WNetAddConnection3 创建同 ...
- WINDOWS API 函数(超长,值得学习)
一.隐藏和显示光标 函数: int ShowCursor ( BOOL bShow ); 参数 bshow,为布尔型,bShow的值为False时隐藏光标,为True时显示光标:该函数的返回值为整型 ...
- linux API函数大全
获取当前执行路径:getcwd1. API之网络函数 WNetAddConnection 创建同一个网络资源的永久性连接 WNetAddConnection2 创建同一个网络资源的连接 WNetAdd ...
- Windows API Finishing
input { font-size: 14px; height: 26px } td { border-style: none; border-color: inherit; border-width ...
- 用 Delphi 7 实现基于 FFMS2 的视频转 GIF 工具 [原创]
儿子经常要把自拍的视频(ts格式)转成表情包,下载了几个工具都不大好用,更多的还要收费.那就想自己写一个吧,没想到这一下断断续续地,居然 3 个月过去了.现在总算弄出个作品来了,结个贴吧.唉,天资愚钝 ...
- Windows API函数大全(精心总结)
WindowsAPI函数大全(精心总结) 目录 1. API之网络函数... 1 2. API之消息函数... 1 3. API之文件处理函数... 2 4. API之打印函数... 5 5. ...
- WINDOWS-API:API函数大全
操作系统除了协调应用程序的执行.内存分配.系统资源管理外,同时也是一个很大的服务中心,调用这个服务中心的各种服务(每一种服务是一个函数),可以帮肋应用程序达到开启视窗.描绘图形.使用周边设备的目的,由 ...
随机推荐
- 帝国CMS-后台使用
后台管理----- 网址wxtoupiao111.com 后台http://wxtoupiao111.com/e/admin/账号密码认证码admin 数据库 账号root 密码空http://wx ...
- android studio 查看包有没有重复引用
在windows下studio内的命令行里面 gradlew :app:dependencies 苹果系统 ./gradlew :app:dependencies
- 系统启动时队列自动下单--ServletContextListener
package com.liying.pear.queue; import javax.servlet.ServletContextEvent; import javax.servlet.Servle ...
- j2ee高级开发技术课程第三周
一.分析Filter例子(轻量级javaee企业应用实战p132) // 执行过滤的核心方法 public void doFilter(ServletRequest request, ServletR ...
- php 通过 strtr 方法来替换文本中指定的内容
通过在文本中指定待替换的内容,如: [{name}] [{age}] 格式可以自己定义, 大概过程: 在文本中定义需要替换的文本内容: 以键值对的方式 组织数据(数组): 用 file_get_con ...
- 使用netfilter_queue改包笔记
系统:centos 7 准备:安装libnetfilter_queue模块,可以yum安装,也可以网上下载rpm包安装 简介:使用iptables在NAT表上创建DNAT与SNAT规则,对数据包进行转 ...
- python服务器环境搭建Flask,uwsgi和nginx
python服务器环境搭建Flask,uwsgi和nginx 环境配置 服务器配置 [部署系统环境Ubuntu] 使用python的Flask框架搭建好网页后台后,便要开始将网站部署到服务器平台了. ...
- 放苹果(poj1664递归)
ti放苹果 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24392 Accepted: 15513 Descripti ...
- c# 连等的写法都做了什么?
在工作中遇到这样一个问题,批量对变量赋值相同的值时,如下: a = ; b = ; c = ; d = ; 我想这样写: a= b = c = d = ; 分别对应IL: Dup 复制计算堆栈上当前最 ...
- Android-消息处理学习总结(Handler,Looper)
参考资料: http://www.cnblogs.com/qlky/p/5657924.html http://blog.csdn.net/guolin_blog/article/details/99 ...