MFC 屏幕截图(libjpeg bmp转jpg)
项目中需要用到的功能。
void Screenshot()
{
CDC *pDC;
pDC = CDC::FromHandle(GetDC(GetDesktopWindow()));
if(pDC == NULL)
return;
int BitPerPixel = pDC->GetDeviceCaps(BITSPIXEL);
int Width = pDC->GetDeviceCaps(HORZRES);
int Height = pDC->GetDeviceCaps(VERTRES); CDC memDC;
if(memDC.CreateCompatibleDC(pDC) == )
return; CBitmap memBitmap, *oldmemBitmap;
if(memBitmap.CreateCompatibleBitmap(pDC, Width, Height) == NULL)
return; oldmemBitmap = memDC.SelectObject(&memBitmap);
if(oldmemBitmap == NULL)
return;
if(memDC.BitBlt(, , Width, Height, pDC, , , SRCCOPY) == )
return; CPoint po;
GetCursorPos(&po);
HICON hinco = (HICON)GetCursor();
memDC.DrawIcon(po.x- , po.y - , hinco); BITMAP bmp;
memBitmap.GetBitmap(&bmp); BITMAPINFOHEADER bih = {};
bih.biBitCount = bmp.bmBitsPixel;
bih.biCompression = BI_RGB;
bih.biHeight = bmp.bmHeight;
bih.biPlanes = ;
bih.biSize = sizeof(BITMAPINFOHEADER);
bih.biSizeImage = bmp.bmWidthBytes * bmp.bmHeight;
bih.biWidth = bmp.bmWidth; BITMAPFILEHEADER bfh = {};
bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bfh.bfSize = bfh.bfOffBits + bmp.bmWidthBytes * bmp.bmHeight;
bfh.bfType = (WORD)0x4d42; BYTE* pImgBuff = new BYTE[bmp.bmWidthBytes * bmp.bmHeight]; GetDIBits(memDC.m_hDC, (HBITMAP) memBitmap.m_hObject
, , Height, pImgBuff, (LPBITMAPINFO) &bih, DIB_RGB_COLORS);
memDC.SelectObject(oldmemBitmap); BYTE* pJpg = NULL;
int nJpgSize = BmpToJpeg(pImgBuff, bmp.bmWidth, bmp.bmHeight, &pJpg); if (NULL != pJpg)
{
delete[] pJpg;
} delete [] pImgBuff;
}
附上 BmpToJpeg
int BmpToJpeg(BYTE *pSrc, int nWidth, int nHeight, BYTE** ppDes)
{
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
JSAMPROW row_pointer[];
int row_stride;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo); DWORD dwLen = nWidth * nHeight * ;
jpeg_mem_dest(&cinfo, ppDes, &dwLen); cinfo.image_width = nWidth;
cinfo.image_height = nHeight;
cinfo.input_components = ;
cinfo.in_color_space = JCS_RGB; jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, JPEG_QUALITY, TRUE);
jpeg_start_compress(&cinfo, TRUE); row_stride = nWidth * ;
for (int i=, j=; j < nWidth*nHeight*; i+=, j+=) //BGRA => RGB
{
*(pSrc+i)=*(pSrc+j+);
*(pSrc+i+)=*(pSrc+j+);
*(pSrc+i+)=*(pSrc+j);
} while (cinfo.next_scanline < cinfo.image_height)
{
row_pointer[] = &pSrc[(cinfo.image_height - cinfo.next_scanline - ) * row_stride];
(void) jpeg_write_scanlines(&cinfo, row_pointer, );
}
jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo);
return dwLen;
}
需要用到的头文件
#define JPEG_QUALITY 50
extern "C"
{
#include "jpeglib.h"
#include "jmorecfg.h"
#include "jconfig.h"
}
MFC 屏幕截图(libjpeg bmp转jpg)的更多相关文章
- 远程控制编写之屏幕传输 MFC实现 屏幕截图 发送bmp数据 显示bmp图像
远程控制编写之屏幕传输 MFC实现 屏幕截图 发送bmp数据 显示bmp图像: 一 : 首先要了解bmp图像的结构 详情请看我转载的一篇文章http://blog.csdn.net/hnust_x ...
- MFC对话框显示BMP图片
1.MFC对话框显示BMP图片我们先从简单的开始吧.先分一个类: (一) 非动态显示图片(即图片先通过资源管理器载入,有一个固定ID) (二) 动态载入图片(即只需要在程序中指定图片的路径即可载入) ...
- MFC中显示 .bmp格式的位图
最近在看VisualC++ 图像处理的书籍,表示一直在从基础做起,今天就记录一个简单功能的实现,显示.bmp格式的位图. 首先需要理解的是窗口创建的过程包括两个步骤:首先擦除窗口的背景,然后在对窗口进 ...
- MFC如何添加bmp文件和ICO文件
1.添加BMP格式文件如下图所示: 2.添加ICO格式文件如下图所示:
- MFC CListCtrl 显示bmp图片
m_ListCtrl.SetExtendedStyle(m_ListCtrl.GetExtendedStyle()| LVS_EX_SUBITEMIMAGES | LVS_EX_GRIDLINES); ...
- MFC 屏幕截图方法
//获取当前屏幕的并且保存图片 LRESULT CFeetScanView::SaveViewBMP(WPARAM wParam, LPARAM lParam) { CRect rect; this- ...
- VS MFC 按键导入BMP图片
1. 图片导入资源: 2.实现代码: 直接给CButton加图片的方法: 1.在资源编辑器中添加一个按钮.把它的Bitmap属性设为true 2.在按钮上点右键,添加一个变量m_Btn(CButton ...
- MFC对话框中显示BMP,JPG图片
//************************************ // 方法说明: 显示JPG和GIF.BMP图片 // 参数说明: CDC * pDC 设 ...
- jpg转bmp(使用libjpeg)
源: jpg转bmp(使用libjpeg) [转]JPEG压缩原理 bmp转jpg(使用libjpeg)
随机推荐
- ethereum(以太坊)(十一)--字节数组(二)
pragma solidity ^0.4.0; contract test { uint [5] T =[1,2,3,4,5] ;//固定长度的数组:可修改数组内值大小,不支持push,不可更改长度 ...
- HTML5--混合布局
1.先上效果图,大家来看看 2.代码如下: <!doctype html> <meta charset='utf-8' content='text/html' /> <h ...
- 4.1 基本类型和引用类型的值【JavaScript高级程序设计第三版】
ECMAScript 变量可能包含两种不同数据类型的值:基本类型值和引用类型值.基本类型值指的是简单的数据段,而引用类型值指那些可能由多个值构成的对象. 在将一个值赋给变量时,解析器必须确定这个值是基 ...
- 详解 JavaScript 中 splice() 方法
splice() 方法是一个比较少用的方法,但是功能确实很好,并且在我们 coding 的时候,经常有需要 splice() 方法,先介绍一下该方法. 在 JavaScript 中 splice() ...
- CLK_SWR=0xe1
STM8 时钟初始化 主时钟切换寄存器(CLK_SWR) http://www.stmcu.org/document/detail/index/id-200090 stm8寄存器数据手册链接
- 裸机——I2C
网上搜了些资料,碍于智商和基础,看不懂, 只有将S5PV210 数据手册关于I2C的部分,翻译记录下,留到以后用. 1.OVERVIEW The S5PV210 RISC microprocessor ...
- [CodeForces948C]Producing Snow(优先队列)
Description 题目链接 Solution 将温度做一个前缀和,用一个优先队列依次处理一遍 思路还是很简单的 Code #include <cstdio> #include < ...
- 字典--数据结构与算法JavaScript描述(7)
字典 字典是一种以键-值对形式存储数据的数据结构. Dictionary 类 Dictionary 类的基础是Array 类,而不是Object 类. function Dictionary( ){ ...
- Java继承的缺点
转载自:https://www.cnblogs.com/xz816111/archive/2018/05/24/9080173.html JAVA中使用到继承就会有两个无法回避的缺点: 1.打破了封装 ...
- 《Cracking the Coding Interview》——第7章:数学和概率论——题目7
2014-03-20 02:29 题目:将质因数只有3, 5, 7的正整数从小到大排列,找出其中第K个. 解法:用三个iterator指向3, 5, 7,每次将对应位置的数分别乘以3, 5, 7,取三 ...