捕获鼠标光标图像并将其转换为缓冲图像c ++ [英] capture mouse cursor image and convert it as a buffered image c++

查看:108
本文介绍了捕获鼠标光标图像并将其转换为缓冲图像c ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我想编写一个捕获鼠标光标图像并将其作为缓冲图像返回的函数(我希望使用该缓冲图像通过jni从Java应用程序接收以构造该图像以供以后使用).我使用下面的代码片段来获取鼠标光标图像. bmi变量将获取图像颜色信息.我打印了光标位图的RGB颜色信息的蓝色分量.我在控制台中得到了二进制结果.我应该获取十六进制值.不是吗?根据我的目的,我的代码有什么问题?有人可以指出我如何获取缓冲的图像,以便可以在Java应用程序中构造它吗?


In my application I want to write a function that capture the mouse cursor image and return it as a buffered image(I hope to use that buffered image to receive from a java application via jni to construct the image for later use). I used below code snippet to get the mouse cursor image. bmi variable will get the image color information. I printed blue component of RGB color information of cursor bit map. I got binary like result in console. I should get hexdecimal values.shouldn''t I?what is the wrong in my code according to my purpose here? can someone pointed me how to get the buffered image so that I can construct it in java application


#include "stdafx.h"
#include <iostream>
#include<windows.h>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	 HBITMAP hbitmap;
	 BITMAP bitmap;
	 BITMAPINFO bmi;
	 HDC hdcScreen = GetDC(NULL);
	 HDC hdcMem = CreateCompatibleDC(hdcScreen);

	 CURSORINFO cursorInfo = { 0 };
         cursorInfo.cbSize = sizeof(cursorInfo);
	 
	 GetCursorInfo(&cursorInfo);
	 
	 ICONINFO ii = {0};
	 GetIconInfo(cursorInfo.hCursor, &ii);
	 
	 hbitmap = ii.hbmColor;	
	 SelectObject(hdcMem, hbitmap);
	 GetObject(hbitmap, sizeof(BITMAP), &bitmap);

	 GetDIBits(hdcMem, hbitmap, 0, 32, NULL, &bmi, DIB_RGB_COLORS);

	 for(int i = 0;i<4096;i++){
		 cout<<bmi.bmiColors[i].rgbBlue;
	 }

	 std::getchar();
	 return 0;
}</windows.h></iostream>

推荐答案

以下内容应为您提供十六进制值:
The following should give you hex values:
cout << hex << bmi.bmiColors[i].rgbBlue;



祝你好运!



Good luck!


这篇关于捕获鼠标光标图像并将其转换为缓冲图像c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆