java像素
1. java 怎麼提取Image對象的像素數據
這個是一段透明化處理的代碼,裡面有獲取像素的代碼存在!希望對你有所幫助!
pixels將是像素,int pixels[] = (int[]) pgr.getPixels();這里將寫入到數組中了!
/**
* 使圖片中的某一種顏色透明
*
* @param image
* Image
* @param RGB16
* String 十六進制的六位顏色值字元串
* @param isFiltrate
* boolean
* @return Image
*/
public static Image setTranImage(Image image, String RGB16,
boolean isFiltrate)
{
int width = image.getWidth(null);
int height = image.getHeight(null);
Image abufferedimage = new BufferedImage(width, height, 2);
Graphics g = abufferedimage.getGraphics();
g.drawImage(image, 0, 0, width, height, 0, 0, width, height, null);
g.dispose();
// 透明化處理
PixelGrabber pgr = new PixelGrabber(abufferedimage, 0, 0, -1, -1, true);
try
{
pgr.grabPixels();
}
catch (InterruptedException ex)
{
ex.getStackTrace();
}
int pixels[] = (int[]) pgr.getPixels();
if (isFiltrate && RGB16.length() == 6)
{
// 循環像素
for (int i = 0; i < pixels.length; i++)
{
// 去色
if (((pixels[i] & 0x00ff0000) >> 16 == Integer.parseInt(
RGB16.substring(0, 2), 16)
&& (pixels[i] & 0x0000ff00) >> 8 == Integer.parseInt(
RGB16.substring(2, 4), 16) && (pixels[i] & 0x000000ff) == Integer
.parseInt(RGB16.substring(4, 6), 16)))
{
// 透明化
pixels[i] = 0;
}
}
}
ImageProcer ip = new MemoryImageSource(pgr.getWidth(),
pgr.getHeight(), pixels, 0, pgr.getWidth());
return toolkit.createImage(ip);
}
2. java 中如何獲得灰度圖像的像素值,getRGB和getRaster有什麼區別
前者是直接取某點的顏色
後者是得到java.awt.image.WritableRaster,再可以進行處理
3. 在java中如何獲得屏幕像素的大小
進去。任務管理器。顯示桌面。屬性。設置。然後自己調 OK了。
4. JAVA中怎麼獲取一個字元串占的像素有什麼方法
字元串占的位元組?像素?
5. Java像素碰撞檢測原理
大體有兩種方式,一種是基於屏幕像素顏色檢測,當移動的目標坐標像素的顏色與目標顏色相同時為發生碰撞。
另一種是坐標檢測,就是維持各感興趣物體的坐標數據,比如大炮打飛機,飛機和炮彈的坐標都保留著,判斷二者坐標相同時為發生碰撞。
6. java 如何獲取圖片的像素值
try{
File _file = new File("C:/Documents and Settings/mayuanfei/My Documents/女友照片.jpg"); //讀入文件
Image src = javax.imageio.ImageIO.read(_file); //構造Image對象
int wideth=src.getWidth(null); //得到源圖寬
int height=src.getHeight(null); //得到源圖長
System.out.println(wideth+","+height);
}catch(Exception e){
e.printStackTrace();
}
7. java設計一個類表示屏幕上的像素
public class Screen{
private int wide;
private int high;
//寫 get set方法
}