如何将 HBITMAP 转换为 JNI 的 BYTE 数组

发布于 2024-11-16 20:13:14 字数 921 浏览 3 评论 0 原文

首先,对不起,我的英语不好,你好,我是这种论坛的新手,我的问题很头痛,好吧,我仍在寻找此页面和其他页面中的所有内容,我找不到解决方案,首先我需要创建屏幕截图并将其保存在 jpeg 字节数组中,我的代码很简单并创建 HBITMAP 但麻烦是将其转换为数组,这是我的代码:

int takeScreenShoot(){
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

HDC screenDC,memDC;
HBITMAP screenBITMAP;
screenDC= GetDC(NULL);
memDC= CreateCompatibleDC(screenDC);
int Height = GetSystemMetrics(SM_CYSCREEN);
int Width = GetSystemMetrics(SM_CXSCREEN);
screenBITMAP = CreateCompatibleBitmap(screenDC,Width,Height);
BitBlt(memDC,0,0,Width,Height,screenDC,0,0,SRCCOPY);

/*
  use GDIplus for transform the image to JPEG and pass to a byte stream
  or somethig like that
*/
ReleaseDC(NULL,memDC);
ReleaseDC(NULL,screenDC);

return 0;

}

好吧,这个代码如果用于练习,我尝试使用 GDI+ 中的 Image 类还有位图,但我找不到将其保存在字节数组中的方法,在某些页面中谈论使用 IStream 但我很难理解它,我需要有人以正确的方式指导我,预先感谢您的帮助:D

first of all sorry by my bad english, Hello i am new in this kind of forum, the question i have is a headache, well i still looking for everywere in this page and other, i can't no find the solution, first i need to create a screen capture and save it in a jpeg byte array, my code is simple and create the HBITMAP but the trouble is convert it to an array, here is my code:

int takeScreenShoot(){
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

HDC screenDC,memDC;
HBITMAP screenBITMAP;
screenDC= GetDC(NULL);
memDC= CreateCompatibleDC(screenDC);
int Height = GetSystemMetrics(SM_CYSCREEN);
int Width = GetSystemMetrics(SM_CXSCREEN);
screenBITMAP = CreateCompatibleBitmap(screenDC,Width,Height);
BitBlt(memDC,0,0,Width,Height,screenDC,0,0,SRCCOPY);

/*
  use GDIplus for transform the image to JPEG and pass to a byte stream
  or somethig like that
*/
ReleaseDC(NULL,memDC);
ReleaseDC(NULL,screenDC);

return 0;

}

well, this code if for practice, i try to use Image class from GDI+ and also Bitmap but i don't find the way to save it in a byte array, in some pages talk to use IStream but is dificult to me understand it, i need someone to direct me in the right way, thanks beforehand for the help :D

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野生奥特曼 2024-11-23 20:13:14

您是否在寻找 GetDIBits?将依赖位图转换为 DIB然后将其流式传输到数组或文件或您想要的任何内容中。

有几个图像库也可以帮助提供想法。 CxImageFreeImage,都具有将 HBITMAP(DDB 和 DIB)转换为字节流的功能。

Are you looking for GetDIBits? Convert a dependent bitmap into a DIB and then stream it into an array or file or whatever you want.

There are several image libraries that can help give ideas as well. CxImage, FreeImage, all have functions to convert HBITMAP (both DDB and DIB) into a stream-o-bytes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文