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函数大全
操作系统除了协调应用程序的执行.内存分配.系统资源管理外,同时也是一个很大的服务中心,调用这个服务中心的各种服务(每一种服务是一个函数),可以帮肋应用程序达到开启视窗.描绘图形.使用周边设备的目的,由 ...
随机推荐
- java信任所有证书
package com.eeepay.cashOut.util; import java.io.BufferedReader; import java.io.DataOutputStream; imp ...
- [Error] 'exit' was not declared in this scope的解决方法
新手刚开始用Linux和c++写程序,可能会出现下面的错误 error: ‘exit’ was not declared in this scope 解决方法是 添加 #include <cst ...
- 【从0到1学javascript】javascript数据结构----数组
javascript中对数组的定义 数组是一种特殊的对象,用来表示偏移量的索引是该对象的属性,索引可以是整数.这些数字索引在内部被转换成字符串类型.这是因为javascript对象中的属性名必须是字符 ...
- JAVA框架之Spring【Spring事务详解】
spring提供的事务管理可以分为两类:编程式的和声明式的.编程式的,比较灵活,但是代码量大,存在重复的代码比较多:声明式的比编程式的更灵活.编程式主要使用transactionTemplate.省略 ...
- SpringBoot + docker + neo4j
下拉镜像 docker pull neo4j 启动镜像 docker run -d -p 7473:7473 -p 7687:7687 -p 7474:7474 neo4j 打开浏览器:http:// ...
- java中this$0 this$1 this$2
import java.lang.reflect.Field; public class Outer {//this$0 public class FirstInner {//this$1 publi ...
- Mybatis在非spring环境下配置文件中使用外部数据源(druidDatasource)
Spring环境下, MyBatis可以通过其本身的增强mybatis-spring提供的org.mybatis.spring.SqlSessionFactoryBean来注入第三方DataSourc ...
- python get请求
#!/usr/bin/python #-*- coding:UTF-8 -*-#coding=utf-8 import requests import time import hashlib impo ...
- Linux 卸载 openjdk
1 卸载 openjdk sudo apt-get purge openjdk*
- 创建自己的共用js库
直至昨晚为止,学习了一个多月的MVC与jQuery,从所做的练习中,发觉jQuery的代码也有跟C#语言一样可以重构,多页面有相同使用的方法函数,均可以放置于一个单独立的js文件或是自定义的js库中. ...