Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java HICON到BuffereImage使jvm在64位上崩溃_Java_64 Bit_Gdi_Jna_Jvm Crash - Fatal编程技术网

Java HICON到BuffereImage使jvm在64位上崩溃

Java HICON到BuffereImage使jvm在64位上崩溃,java,64-bit,gdi,jna,jvm-crash,Java,64 Bit,Gdi,Jna,Jvm Crash,我用这个方法从HICON那里得到一个BuffereImage 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[] lpBitsCol

我用这个方法从HICON那里得到一个BuffereImage

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;
}
预览本机调用工作正常,但在尝试访问gdi32.dll(在其64位版本(位于system32中))时,该方法会崩溃

我正在运行windows 7 64位计算机


谢谢

这通常是因为您的一个或多个参数的大小不正确(32位对64位),或者您的结构的字段定义不适合这两种体系结构。
gdi32.GetDIBits(hDC, piconinfo.hbmColor, 0, height, lpBitsColor, info, DIB_RGB_COLORS);