当前位置:首页 » 编程语言 » java像素

java像素

发布时间: 2022-06-01 21:17:43

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方法
}

热点内容
c语言短路现象 发布:2025-04-23 02:23:54 浏览:301
可运行脚本怎么写 发布:2025-04-23 02:23:09 浏览:324
安卓死亡空间怎么飞行 发布:2025-04-23 02:17:21 浏览:543
安卓机怎么设置语音开机 发布:2025-04-23 02:08:01 浏览:485
mysql存储过程事务控制 发布:2025-04-23 02:02:04 浏览:652
服务器ip承载量 发布:2025-04-23 01:53:37 浏览:595
易语言源码怎么保存 发布:2025-04-23 01:36:28 浏览:160
查看应用数据的存储路径 发布:2025-04-23 01:36:18 浏览:382
winformaccess数据库 发布:2025-04-23 01:31:20 浏览:166
免费申请腾讯云服务器 发布:2025-04-23 01:23:12 浏览:731