这是哪个对象的,能不能具体举例!
解决方案 »
- java swing窗体中显示word文档
- 為什麽keyListener不能監聽tab鍵
- JAVA做一个字母3角形``
- 日志方面的帮助
- jxl在excel中插入形状并在形状上写字 在线等待
- bookURL = TreeDemo.class.getResource(filename)??中的那个class是怎么回事??
- 读大txt文件,写入数据库.提高速度的办法.
- Linux下运行JAVA出现的怪事
- double q=019e-13f,这个表达式怎么编译通过了,0开头的不是8进制的吗?
- 车牌号码之迷(用编程来解)!我错什么地方啊?
- 卖29日北京到重庆的1389次火车票卧铺
- 菜鸟初次使用包就出错,父老乡亲帮忙看看啊.
// Get the color of a specific pixel
import java.awt.image.PixelGrabber;
import java.awt.Image;
import javax.swing.ImageIcon;
import java.awt.image.PixelGrabber;
import java.lang.InterruptedException;public class PixelColor
{
public static void main(String[] args)
{
ImageIcon imageIcon = new ImageIcon("sample.jpg");
Image picture = imageIcon.getImage();
int height = imageIcon.getIconHeight();
int width = imageIcon.getIconWidth(); int[] pixels = new int[width * height];
PixelGrabber pg = new PixelGrabber(picture, 0, 0, width, height, pixels, 0, width);
try
{
pg.grabPixels();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
// point(x,y)
int x = 3;
int y = 3;
int pixel = pixels[x + y * width];
int alpha = (pixel >> 24) & 0xff;
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel ) & 0xff;
System.out.println("height: " + height);
System.out.println("width: " + width); System.out.println("alpha: " + alpha);
System.out.println("red: " + red);
System.out.println("green: " + green);
System.out.println("blue: " + blue);
}
}