当前位置:首页 » 编程语言 » 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++){

热点内容
java返回this 发布:2025-10-20 08:28:16 浏览:595
制作脚本网站 发布:2025-10-20 08:17:34 浏览:889
python中的init方法 发布:2025-10-20 08:17:33 浏览:583
图案密码什么意思 发布:2025-10-20 08:16:56 浏览:766
怎么清理微信视频缓存 发布:2025-10-20 08:12:37 浏览:687
c语言编译器怎么看执行过程 发布:2025-10-20 08:00:32 浏览:1015
邮箱如何填写发信服务器 发布:2025-10-20 07:45:27 浏览:258
shell脚本入门案例 发布:2025-10-20 07:44:45 浏览:117
怎么上传照片浏览上传 发布:2025-10-20 07:44:03 浏览:808
python股票数据获取 发布:2025-10-20 07:39:44 浏览:715