本文整理汇总了Java中com.sun.jna.platform.win32.GDI32类的典型用法代码示例。如果您正苦于以下问题:Java GDI32类的具体用法?Java GDI32怎么用?Java GDI32使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GDI32类属于com.sun.jna.platform.win32包,在下文中一共展示了GDI32类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getIcon
import com.sun.jna.platform.win32.GDI32; //导入依赖的package包/类
/**
* Gets the icon that corresponds to a given icon handler.
*
* @param hIcon
* Handler to the icon to get
* @return The icon that corresponds to a given icon handler
*/
public static BufferedImage getIcon(final HICON hIcon) {
final int width = ICON_SIZE;
final int height = ICON_SIZE;
final short depth = ICON_DEPTH;
final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
final Memory lpBitsColor = new Memory(width * height * depth / ICON_BYTE_SIZE);
final Memory lpBitsMask = new Memory(width * height * depth / ICON_BYTE_SIZE);
final BITMAPINFO info = new BITMAPINFO();
final BITMAPINFOHEADER hdr = new BITMAPINFOHEADER();
info.bmiHeader = hdr;
hdr.biWidth = width;
hdr.biHeight = height;
hdr.biPlanes = 1;
hdr.biBitCount = depth;
hdr.biCompression = WinGDI.BI_RGB;
final HDC hDC = User32.INSTANCE.GetDC(null);
final ICONINFO piconinfo = new ICONINFO();
User32.INSTANCE.GetIconInfo(hIcon, piconinfo);
GDI32.INSTANCE.GetDIBits(hDC, piconinfo.hbmColor, 0, height, lpBitsColor, info, WinGDI.DIB_RGB_COLORS);
GDI32.INSTANCE.GetDIBits(hDC, piconinfo.hbmMask, 0, height, lpBitsMask, info, WinGDI.DIB_RGB_COLORS);
int r, g, b, a, argb;
int x = 0, y = height - 1;
for (int i = 0; i < lpBitsColor.size(); i = i + 3) {
b = lpBitsColor.getByte(i) & 0xFF;
g = lpBitsColor.getByte(i + 1) & 0xFF;
r = lpBitsColor.getByte(i + 2) & 0xFF;
a = 0xFF - lpBitsMask.getByte(i) & 0xFF;
argb = a << 24 | r << 16 | g << 8 | b;
image.setRGB(x, y, argb);
x = (x + 1) % width;
if (x == 0) {
y--;
}
}
User32.INSTANCE.ReleaseDC(null, hDC);
GDI32.INSTANCE.DeleteObject(piconinfo.hbmColor);
GDI32.INSTANCE.DeleteObject(piconinfo.hbmMask);
return image;
}
开发者ID:ZabuzaW,项目名称:Mem-Eater-Bug,代码行数:54,代码来源:User32Util.java
示例2: capture
import com.sun.jna.platform.win32.GDI32; //导入依赖的package包/类
public BufferedImage capture(final HWND hWnd) {
final HDC hdcWindow = User32.INSTANCE.GetDC(hWnd);
final HDC hdcMemDC = GDI32.INSTANCE.CreateCompatibleDC(hdcWindow);
final RECT bounds = new RECT();
User32Extra.INSTANCE.GetClientRect(hWnd, bounds);
final int width = bounds.right - bounds.left;
final int height = bounds.bottom - bounds.top;
if (width * height <= 0) { return null; }
final HBITMAP hBitmap = GDI32.INSTANCE.CreateCompatibleBitmap(hdcWindow, width, height);
final HANDLE hOld = GDI32.INSTANCE.SelectObject(hdcMemDC, hBitmap);
GDI32Extra.INSTANCE.BitBlt(hdcMemDC, 0, 0, width, height, hdcWindow, 0, 0, WinGDIExtra.SRCCOPY);
GDI32.INSTANCE.SelectObject(hdcMemDC, hOld);
GDI32.INSTANCE.DeleteDC(hdcMemDC);
final BITMAPINFO bmi = new BITMAPINFO();
bmi.bmiHeader.biWidth = width;
bmi.bmiHeader.biHeight = -height;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = WinGDI.BI_RGB;
final Memory buffer = new Memory(width * height * 4);
GDI32.INSTANCE.GetDIBits(hdcWindow, hBitmap, 0, height, buffer, bmi, WinGDI.DIB_RGB_COLORS);
final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
image.setRGB(0, 0, width, height, buffer.getIntArray(0, width * height), 0, width);
GDI32.INSTANCE.DeleteObject(hBitmap);
User32.INSTANCE.ReleaseDC(hWnd, hdcWindow);
return image;
}
开发者ID:friedlwo,项目名称:AppWoksUtils,代码行数:39,代码来源:Paint.java
示例3: getImageByHICON
import com.sun.jna.platform.win32.GDI32; //导入依赖的package包/类
public static BufferedImage getImageByHICON(final int width, final int height, final HANDLE hicon, final BITMAPINFOHEADER info) {
final IconInfo iconinfo = new org.appwork.jna.winapi.structs.IconInfo();
try {
// GDI32 g32 = GDI32.INSTANCE;
// get icon information
if (!User.I.GetIconInfo(new HICON(hicon.getPointer()), iconinfo)) { return null; }
final HWND hwdn = new HWND();
final HDC dc = User32.INSTANCE.GetDC(hwdn);
if (dc == null) {
return null; }
try {
final int nBits = width * height * 4;
// final BitmapInfo bmi = new BitmapInfo(1);
final Memory colorBitsMem = new Memory(nBits);
// // Extract the color bitmap
final BITMAPINFO bmi = new WinGDI.BITMAPINFO();
bmi.bmiHeader.biWidth = width;
bmi.bmiHeader.biHeight = -height;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = WinGDI.BI_RGB;
GDI32.INSTANCE.GetDIBits(dc, iconinfo.hbmColor, 0, height, colorBitsMem, bmi, WinGDI.DIB_RGB_COLORS);
// g32.GetDIBits(dc, iconinfo.hbmColor, 0, size, colorBitsMem,
// bmi,
// GDI32.DIB_RGB_COLORS);
final int[] colorBits = colorBitsMem.getIntArray(0, width * height);
if (info.biBitCount < 32) {
final Memory maskBitsMem = new Memory(nBits);
// // Extract the mask bitmap
GDI32.INSTANCE.GetDIBits(dc, iconinfo.hbmMask, 0, height, maskBitsMem, bmi, WinGDI.DIB_PAL_COLORS);
// g32.GetDIBits(dc, iconinfo.hbmMask, 0, size,
// maskBitsMem,
// bmi,
// // GDI32.DIB_RGB_COLORS);
final int[] maskBits = maskBitsMem.getIntArray(0, width * height);
// // // Copy the mask alphas into the color bits
for (int i = 0; i < colorBits.length; i++) {
colorBits[i] = colorBits[i] | (maskBits[i] != 0 ? 0 : 0xFF000000);
}
}
final BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
bi.setRGB(0, 0, width, height, colorBits, 0, height);
return bi;
} finally {
com.sun.jna.platform.win32.User32.INSTANCE.ReleaseDC(hwdn, dc);
}
} finally {
User32.INSTANCE.DestroyIcon(new HICON(hicon.getPointer()));
GDI32.INSTANCE.DeleteObject(iconinfo.hbmColor);
GDI32.INSTANCE.DeleteObject(iconinfo.hbmMask);
}
}
开发者ID:friedlwo,项目名称:AppWoksUtils,代码行数:60,代码来源:Main.java
示例4: getImageByHICON
import com.sun.jna.platform.win32.GDI32; //导入依赖的package包/类
public static BufferedImage getImageByHICON(final int width, final int height, final HANDLE hicon) {
final IconInfo iconinfo = new org.appwork.jna.winapi.structs.IconInfo();
try {
// GDI32 g32 = GDI32.INSTANCE;
// get icon information
if (!org.appwork.jna.winapi.user32.User.I.GetIconInfo(new HICON(hicon.getPointer()), iconinfo)) { return null; }
final HWND hwdn = new HWND();
final HDC dc = User32.INSTANCE.GetDC(hwdn);
if (dc == null) {
return null; }
try {
final int nBits = width * height * 4;
// final BitmapInfo bmi = new BitmapInfo(1);
final Memory colorBitsMem = new Memory(nBits);
// // Extract the color bitmap
final BITMAPINFO bmi = new WinGDI.BITMAPINFO();
bmi.bmiHeader.biWidth = width;
bmi.bmiHeader.biHeight = -height;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = WinGDI.BI_RGB;
GDI32.INSTANCE.GetDIBits(dc, iconinfo.hbmColor, 0, height, colorBitsMem, bmi, WinGDI.DIB_RGB_COLORS);
// g32.GetDIBits(dc, iconinfo.hbmColor, 0, size, colorBitsMem,
// bmi,
// GDI32.DIB_RGB_COLORS);
final int[] colorBits = colorBitsMem.getIntArray(0, width * height);
// final Memory maskBitsMem = new Memory(nBits);
// // // Extract the mask bitmap
// GDI32.INSTANCE.GetDIBits(dc, iconinfo.hbmMask, 0, height,
// maskBitsMem, bmi, WinGDI.DIB_PAL_COLORS);
// // g32.GetDIBits(dc, iconinfo.hbmMask, 0, size, maskBitsMem,
// bmi,
// // GDI32.DIB_RGB_COLORS);
// final int[] maskBits = maskBitsMem.getIntArray(0, width *
// height);
// // // Copy the mask alphas into the color bits
// for (int i = 0; i < colorBits.length; i++) {
// colorBits[i] = colorBits[i] | (maskBits[i] != 0 ? 0 :
// 0xFF000000);
// }
// // Release DC
// Main.u32.ReleaseDC(0, dc);
//
// // Release bitmap handle in icon info
// g32.DeleteObject(iconinfo.hbmColor); // add
// g32.DeleteObject(iconinfo.hbmMask); // add
final BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
bi.setRGB(0, 0, width, height, colorBits, 0, height);
return bi;
} finally {
com.sun.jna.platform.win32.User32.INSTANCE.ReleaseDC(hwdn, dc);
}
} finally {
User32.INSTANCE.DestroyIcon(new HICON(hicon.getPointer()));
GDI32.INSTANCE.DeleteObject(iconinfo.hbmColor);
GDI32.INSTANCE.DeleteObject(iconinfo.hbmMask);
}
}
开发者ID:friedlwo,项目名称:AppWoksUtils,代码行数:69,代码来源:FileIconExporter.java
示例5: capture
import com.sun.jna.platform.win32.GDI32; //导入依赖的package包/类
private static BufferedImage capture(HWND hWnd) throws WindowNotFoundException {
HDC hdcWindow = User32.INSTANCE.GetDC(hWnd);
HDC hdcMemDC = GDI32.INSTANCE.CreateCompatibleDC(hdcWindow);
RECT bounds = new RECT();
User32Extra.INSTANCE.GetClientRect(hWnd, bounds);
int width = bounds.right - bounds.left;
int height = bounds.bottom - bounds.top;
if(width == 0 || height == 0) throw new peeknick.errormanager.WindowNotFoundException();
HBITMAP hBitmap = GDI32.INSTANCE.CreateCompatibleBitmap(hdcWindow, width, height);
HANDLE hOld = GDI32.INSTANCE.SelectObject(hdcMemDC, hBitmap);
GDI32Extra.INSTANCE.BitBlt(hdcMemDC, 0, 0, width, height, hdcWindow, 0, 0, WinGDIExtra.SRCCOPY);
GDI32.INSTANCE.SelectObject(hdcMemDC, hOld);
GDI32.INSTANCE.DeleteDC(hdcMemDC);
BITMAPINFO bmi = new BITMAPINFO();
bmi.bmiHeader.biWidth = width;
bmi.bmiHeader.biHeight = -height;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = WinGDI.BI_RGB;
Memory buffer = new Memory(width * height * 4);
GDI32.INSTANCE.GetDIBits(hdcWindow, hBitmap, 0, height, buffer, bmi, WinGDI.DIB_RGB_COLORS);
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
image.setRGB(0, 0, width, height, buffer.getIntArray(0, width * height), 0, width);
GDI32.INSTANCE.DeleteObject(hBitmap);
User32.INSTANCE.ReleaseDC(hWnd, hdcWindow);
return image;
}
开发者ID:jardiacaj,项目名称:peeknick,代码行数:41,代码来源:Paint.java
注:本文中的com.sun.jna.platform.win32.GDI32类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论