Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 177489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:03:48+00:00 2026-05-11T14:03:48+00:00

I was wondering if there is a way to extract an Image object from

  • 0

I was wondering if there is a way to extract an Image object from a Cursor object in Java.

A use for this would be for instance :

Image img = extractCursorImage(Cursor.getDefaultCursor()); 

Which you then can draw on a toolbar button (that’s the purpose I want it for).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T14:03:49+00:00Added an answer on May 11, 2026 at 2:03 pm

    The Cursor class is pretty abstract – all the important stuff is delegated to native code, so you can’t just draw one onto at graphics context. There isn’t an immediately obvious way of getting round the need to either predefine the icons or do it in native code.


    could you help me use that function you mentioned?

    Below is some code to draw built-in Windows cursors using the JNA library. If you can use JNA, you can avoid C++ compilers.

    I’m probably making too many native calls, but the cost is not significant for one-shot icon generation.

    hand cursor drawn in Java http://f.imagehost.org/0709/hand.png

    Code to display a cursor as a Java image:

    public class LoadCursor {    public static void draw(BufferedImage image, int cursor,       int diFlags) {     int width = image.getWidth();     int height = image.getHeight();      User32 user32 = User32.INSTANCE;     Gdi32 gdi32 = Gdi32.INSTANCE;      Pointer hIcon = user32         .LoadCursorW(Pointer.NULL, cursor);     Pointer hdc = gdi32.CreateCompatibleDC(Pointer.NULL);     Pointer bitmap = gdi32.CreateCompatibleBitmap(hdc,         width, height);      gdi32.SelectObject(hdc, bitmap);     user32.DrawIconEx(hdc, 0, 0, hIcon, width, height, 0,         Pointer.NULL, diFlags);      for (int x = 0; x < width; x++) {       for (int y = 0; y < width; y++) {         int rgb = gdi32.GetPixel(hdc, x, y);         image.setRGB(x, y, rgb);       }     }      gdi32.DeleteObject(bitmap);     gdi32.DeleteDC(hdc);   }    public static void main(String[] args) {     final int width = 128;     final int height = 128;      BufferedImage image = new BufferedImage(width, height,         BufferedImage.TYPE_INT_ARGB);     draw(image, User32.IDC_HAND, User32.DI_NORMAL);     BufferedImage mask = new BufferedImage(width, height,         BufferedImage.TYPE_INT_RGB);     draw(mask, User32.IDC_HAND, User32.DI_MASK);     applyMask(image, mask);      JLabel icon = new JLabel();     icon.setIcon(new ImageIcon(image));      JFrame frame = new JFrame();     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     frame.setContentPane(icon);     frame.pack();     frame.setVisible(true);   }    private static void applyMask(BufferedImage image,       BufferedImage mask) {     int width = image.getWidth();     int height = image.getHeight();     for (int x = 0; x < width; x++) {       for (int y = 0; y < height; y++) {         int masked = mask.getRGB(x, y);         if ((masked & 0x00FFFFFF) == 0) {           int rgb = image.getRGB(x, y);           rgb = 0xFF000000 | rgb;           image.setRGB(x, y, rgb);         }       }     }   }  } 

    User32.dll interface:

    public interface User32 extends Library {    public static User32 INSTANCE = (User32) Native       .loadLibrary('User32', User32.class);    /** @see #LoadCursorW(Pointer, int) */   public static final int IDC_ARROW = 32512;   /** @see #LoadCursorW(Pointer, int) */   public static final int IDC_IBEAM = 32513;   /** @see #LoadCursorW(Pointer, int) */   public static final int IDC_WAIT = 32514;   /** @see #LoadCursorW(Pointer, int) */   public static final int IDC_CROSS = 32515;   /** @see #LoadCursorW(Pointer, int) */   public static final int IDC_UPARROW = 32516;   /** @see #LoadCursorW(Pointer, int) */   public static final int IDC_SIZENWSE = 32642;   /** @see #LoadCursorW(Pointer, int) */   public static final int IDC_SIZENESW = 32643;   /** @see #LoadCursorW(Pointer, int) */   public static final int IDC_SIZEWE = 32644;   /** @see #LoadCursorW(Pointer, int) */   public static final int IDC_SIZENS = 32645;   /** @see #LoadCursorW(Pointer, int) */   public static final int IDC_SIZEALL = 32646;   /** @see #LoadCursorW(Pointer, int) */   public static final int IDC_NO = 32648;   /** @see #LoadCursorW(Pointer, int) */   public static final int IDC_HAND = 32649;   /** @see #LoadCursorW(Pointer, int) */   public static final int IDC_APPSTARTING = 32650;   /** @see #LoadCursorW(Pointer, int) */   public static final int IDC_HELP = 32651;   /** @see #LoadCursorW(Pointer, int) */   public static final int IDC_ICON = 32641;   /** @see #LoadCursorW(Pointer, int) */   public static final int IDC_SIZE = 32640;    /** @see #DrawIconEx(Pointer, int, int, Pointer, int, int, int, Pointer, int) */   public static final int DI_COMPAT = 4;   /** @see #DrawIconEx(Pointer, int, int, Pointer, int, int, int, Pointer, int) */   public static final int DI_DEFAULTSIZE = 8;   /** @see #DrawIconEx(Pointer, int, int, Pointer, int, int, int, Pointer, int) */   public static final int DI_IMAGE = 2;   /** @see #DrawIconEx(Pointer, int, int, Pointer, int, int, int, Pointer, int) */   public static final int DI_MASK = 1;   /** @see #DrawIconEx(Pointer, int, int, Pointer, int, int, int, Pointer, int) */   public static final int DI_NORMAL = 3;   /** @see #DrawIconEx(Pointer, int, int, Pointer, int, int, int, Pointer, int) */   public static final int DI_APPBANDING = 1;    /** http://msdn.microsoft.com/en-us/library/ms648391(VS.85).aspx */   public Pointer LoadCursorW(Pointer hInstance,       int lpCursorName);    /** http://msdn.microsoft.com/en-us/library/ms648065(VS.85).aspx */   public boolean DrawIconEx(Pointer hdc, int xLeft,       int yTop, Pointer hIcon, int cxWidth, int cyWidth,       int istepIfAniCur, Pointer hbrFlickerFreeDraw,       int diFlags);  } 

    Gdi32.dll interface:

    public interface Gdi32 extends Library {    public static Gdi32 INSTANCE = (Gdi32) Native       .loadLibrary('Gdi32', Gdi32.class);    /** http://msdn.microsoft.com/en-us/library/dd183489(VS.85).aspx */   public Pointer CreateCompatibleDC(Pointer hdc);    /** http://msdn.microsoft.com/en-us/library/dd183488(VS.85).aspx */   public Pointer CreateCompatibleBitmap(Pointer hdc,       int nWidth, int nHeight);    /** http://msdn.microsoft.com/en-us/library/dd162957(VS.85).aspx */   public Pointer SelectObject(Pointer hdc, Pointer hgdiobj);    /** http://msdn.microsoft.com/en-us/library/dd145078(VS.85).aspx */   public int SetPixel(Pointer hdc, int X, int Y, int crColor);    /** http://msdn.microsoft.com/en-us/library/dd144909(VS.85).aspx */   public int GetPixel(Pointer hdc, int nXPos, int nYPos);    /** http://msdn.microsoft.com/en-us/library/dd183539(VS.85).aspx */   public boolean DeleteObject(Pointer hObject);    /** http://msdn.microsoft.com/en-us/library/dd183533(VS.85).aspx */   public boolean DeleteDC(Pointer hdc);  } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if there were a way to extract information from an objective-c
Wondering if there is any way to get the lambda expressions that result from
I was wondering if there's a way to export package information from Cognos 8
I was wondering if there was a way to extract all the values of
I was wondering if there is a way I can extract everything before I
I was wondering if there was a quick way to extract keys of associative
I'm wondering if there is a way to extract the necessary data out of
I was wondering is there a way to escape all html tags from a
I was wondering is there a way in PHP that you could tell where
I am wondering is there a way to render a partial view in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.