I changed the cursor Icon whenever a certain toggle button is clicked. But the loaded image contains an extra pixel in it at the bottom corner! It's annoying, like there's constant dirt on the screen. I created the cursor icon using junior icon editor. When I open the picture using windows photo viewer or photoshop, the pixel doesn't manifest itself. It only shows when I use it in the application.
The application is a Java application, and this is how I set the cursor.
Image img = getResourceMap().getImageIcon( iconFilename ).getImage();
Cursor newCursor = Toolkit.getDefaultToolkit().createCustomCursor( img,
new Point( 5, 5 ), "cursor" );
Does anyone know what could be the possible reasons for this extra shaded pixel? It occurs right below the east-facing arrow, about 2 milimeters below it.

You can see the effect running this code. The image appears as expected in a label, but as a pointer there is a darkened pixel on the lower left.
import java.awt.*;
import java.awt.image.BufferedImage;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.imageio.ImageIO;
import java.net.URL;
class ShowImage {
public static void main(String[] args) throws Exception {
URL url = new URL("https://i.sstatic.net/kP1jv.png");
final BufferedImage img = ImageIO.read(url);
System.out.println(
"Image is: " + img.getWidth() + "x" + img.getHeight());
SwingUtilities.invokeLater( new Runnable() {
public void run() {
JLabel l = new JLabel(new ImageIcon(img));
l.setBorder(new EmptyBorder(5,5,5,5));
l.setOpaque(true);
l.setBackground(Color.GREEN.darker());
Cursor newCursor = Toolkit.getDefaultToolkit().
createCustomCursor( img,new Point( 5, 5 ), "c" );
l.setCursor(newCursor);
JOptionPane.showMessageDialog(null, l);
}
});
}
}
At first i thought that we were specifying a bigger image than the system cursor size could handle but than i realized that if we remove the last column(!!) of pixels it worked fine!! I don't know how to explain this!
BufferedImage originalImg = ImageIO.read(new File("kP1jv.png"));
System.out.println("originalImage is: " + originalImg.getWidth() + "x"
+ originalImg.getHeight());
Dimension d = Toolkit.getDefaultToolkit().getBestCursorSize(
originalImg.getWidth(), originalImg.getHeight());
final BufferedImage img = originalImg.getSubimage(0, 0, d.width/*-1*/, d.height-1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With