我使用此方法从HICON获取BufferedImage
public BufferedImage getIcon(Pointer hIcon) {
int width =16;
int height=16;
short depth =24;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
byte[] lpBitsColor = new byte[width*height*depth/8];
byte[] lpBitsMask = new byte[width*height*depth/8];
BITMAPINFO info = new BITMAPINFO();
BITMAPINFOHEADER hdr= new BITMAPINFOHEADER();
info.bmiHeader =hdr;
hdr.biWidth =width;
hdr.biHeight =height;
hdr.biPlanes =1;
hdr.biBitCount =depth;
hdr.biCompression=BI_RGB;
Pointer hDC =u32.GetDC(null);
ICONINFO piconinfo = new ICONINFO();
u32.GetIconInfo(hIcon, piconinfo);
gdi32.GetDIBits(hDC, piconinfo.hbmColor, 0, height, lpBitsColor, info, DIB_RGB_COLORS);
gdi32.GetDIBits(hDC, piconinfo.hbmMask , 0, height, lpBitsMask , info, DIB_RGB_COLORS);
int r, g, b, a, argb;
int x=0, y=height-1;
for (int i = 0; i < lpBitsColor.length; i=i+3) {
b = lpBitsColor[i ] & 0xFF;
g = lpBitsColor[i+1] & 0xFF;
r = lpBitsColor[i+2] & 0xFF;
a = 0xFF-lpBitsMask [i ] & 0xFF;
//System.out.println(lpBitsMask[i]+" "+lpBitsMask[i+1]+" "+lpBitsMask[i+2]);
argb= (a<<24) | (r<<16) | (g<<8) | b;
image.setRGB(x, y, argb);
x=(x+1)%width;
if (x==0) y--;
}
u32.ReleaseDC(null, hDC);
return image;
}
当我将构建路径更改为32位jre时,该方法就像魅力一样工作, 但是当构建路径是64位jre并尝试调试它时,JVM在此行上发生访问冲突时崩溃:
gdi32.GetDIBits(hDC, piconinfo.hbmColor, 0, height, lpBitsColor, info, DIB_RGB_COLORS);
预览本机调用工作正常,但在尝试访问gdi32.dll(在其64位版本(位于system32上))时,此方法崩溃了。
即时运行Windows 7 64位机器
由于