开发者

How to convert HBITMAP to BYTE array for JNI

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 unde开发者_JAVA百科rstand it, i need someone to direct me in the right way, thanks beforehand for the help :D


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜