當前位置:首頁 » 編程語言 » java圖片像素

java圖片像素

發布時間: 2023-03-06 03:24:17

A. java 中如何獲得灰度圖像的像素值,getRGB和getRaster有什麼區別

前者是直接取某點的顏色
後者是得到java.awt.image.WritableRaster,再可以進行處理

B. 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();
}

C. JAVA中怎麼把一個icon的圖片像素變小

1、可以使用BufferedImage 縮小

2、JLabel 可以縮小

D. 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);
}

E. java 怎麼得到一張bmp圖片的像素數組

//我在程序中列印出了每一個坐標的RGB值,你自己整理整理,求個平均值,
//放到你的那個二維數組里。

//自己用畫圖工具做一個小圖片,注意圖片的名字和程序中一致哦~

import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.*;

public class Test{
public static void main(String args[]) {
int[] rgb = new int[3];

File file = new File("a.bmp");
BufferedImage bi=null;
try{
bi = ImageIO.read(file);
}catch(Exception e){
e.printStackTrace();
}

int width=bi.getWidth();
int height=bi.getHeight();
int minx=bi.getMinX();
int miny=bi.getMinY();
System.out.println("width="+width+",height="+height+".");
System.out.println("minx="+minx+",miniy="+miny+".");

for(int i=minx;i<width;i++){

熱點內容
怎樣刪除小視頻文件夾 發布:2024-05-19 05:49:29 瀏覽:589
開啟php短標簽 發布:2024-05-19 05:44:12 瀏覽:473
android各國語言 發布:2024-05-19 05:42:54 瀏覽:247
微信什麼資料都沒怎麼找回密碼 發布:2024-05-19 05:35:34 瀏覽:907
填志願密碼是什麼 發布:2024-05-19 05:30:23 瀏覽:318
城堡爭霸自動掠奪腳本 發布:2024-05-19 05:22:06 瀏覽:204
asp編程工具 發布:2024-05-19 05:20:36 瀏覽:143
insertpython 發布:2024-05-19 05:12:26 瀏覽:244
androidant編譯 發布:2024-05-19 05:04:11 瀏覽:988
按鍵腳本優化 發布:2024-05-19 04:59:57 瀏覽:752