code: public Point pointToPixel(Point p, boolean clipToImage) {
  		Point2D.Double fp=new Point2D.Double(p.x+.5, p.y+.5);
  		try {
  			getImageTransform().inverseTransform(fp, fp);
  		} catch (NoninvertibleTransformException ex) {
  			throw new Error("Image transformation not invertible");
  		}
  		p.x=(int)Math.floor(fp.x);
  		p.y=(int)Math.floor(fp.y);
  		if (clipToImage && (p.x < 0 || p.y < 0 || p.x >= image.getWidth() || p.y >= image.getHeight())) {
  			return null;
  		}
  		return p;
  	}
docs: Returns the image pixel corresponding to the given point. If the <code>clipToImage</code>
  parameter is <code>false</code>, then the function will return an appropriately positioned
  pixel on an infinite plane, even if the point is outside the image bounds. If
  <code>clipToImage</code> is <code>true</code> then the function will return <code>null</code>
  for such positions, and any non-null return value will be a valid image pixel.
  @param p a point in component coordinate system
  @param clipToImage whether the function should return <code>null</code> for positions outside
  the image bounds
  @return the corresponding image pixel
  @throws IllegalStateException if there is no image set or if the size of the viewer is 0 (for example because
  it is not in a visible component)