如果给图中的某个区域动态着色? 图片如: 一张餐桌,餐桌旁有五个形状不一样的凳子,如何动态精确得给凳子进行着色?java api可以实现吗? thx 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 有一种方法,先创一个数组用于放置象素信息;然后对每个象素进行颜色调整;不过这种方法要求你的凳子颜色必须不和其他地方一样;具体方法:Image foreground;//背景图像和前景图像 Image foreground_new;//依据前景图像生成的新图像 MediaTracker mt;int foreground_data[];//用来生成新图像的内存数据 PixelGrabber pg; ……foreground=getImage(getCodeBase(),"xxx.gif"); mt=new MediaTracker(this); mt.addImage(foreground,1); try{mt.waitForAll();} // 等待所有图片的数据都被正确载入 catch(InterruptedException e){ } foreground_data=new int[foreground.getWidth(this) * foreground.getHeight(this)];//初始化 //下面把前景图片的数据载入数组 pg=new PixelGrabber(foreground,0,0,foreground.getWidth(this),foreground.getHeight(this),foreground_data,0,foreground.getWidth(this)); try{pg.grabPixels();} catch(InterruptedException e){ } int colorData=xffffffff(凳子的颜色数据,自己定义);for (int i=0;i<(foreground.getWidth(this) * foreground.getHeight(this));i++)//逐点处理 { if (foreground_data[i]==colorData)//假如这个点的值和凳子颜色的值同 foreground_data[i]=xffffffff(另一种颜色的值)} foreground_new=createImage(new MemoryImageSource(foreground.getWidth(this),foreground.getHeight(this),foreground_data,0,foreground.getWidth(this)));//生成前景图象 ……} 还有就是先将背景和桌子画上面板,然后将凳子作为另一张图片画上去,凳子的背景设成透明(只要用photoshop做一下然后导出为gif图象)然后再用上述方法为凳子改变颜色,只要检查每个象素的第一个字节是不是ff(完全透明).然后把不透明的象素颜色给改了其他暂时没象出来... SQL 掉课了怎么办· 如何避免使用静态方法? Thread跟Runable有什么区别? SWT的browser如何直接获得焦点 使用cobertura插件生成测试覆盖报告的问题。 一个有关JTextField的问题 关于面向对象的一个小问题~ 线程在wait之后,还未notify之前能否结束? 又是一个奇怪路径问题 请大家给我公司足球队起个名。 关于Spring的问题啊,大人帮忙哈 请问50KB左右的图片作为背景加载一般要多长时间?
Image foreground;//背景图像和前景图像 Image foreground_new;//依据前景图像生成的新图像 MediaTracker mt;int foreground_data[];//用来生成新图像的内存数据 PixelGrabber pg; ……foreground=getImage(getCodeBase(),"xxx.gif"); mt=new MediaTracker(this);
mt.addImage(foreground,1); try{mt.waitForAll();} // 等待所有图片的数据都被正确载入 catch(InterruptedException e){ } foreground_data=new int[foreground.getWidth(this) * foreground.getHeight(this)];//初始化 //下面把前景图片的数据载入数组 pg=new PixelGrabber(foreground,0,0,foreground.getWidth(this),foreground.getHeight(this),foreground_data,0,foreground.getWidth(this)); try{pg.grabPixels();} catch(InterruptedException e){ } int colorData=xffffffff(凳子的颜色数据,自己定义);for (int i=0;i<(foreground.getWidth(this) * foreground.getHeight(this));i++)//逐点处理 { if (foreground_data[i]==colorData)//假如这个点的值和凳子颜色的值同 foreground_data[i]=xffffffff(另一种颜色的值)} foreground_new=createImage(new MemoryImageSource(foreground.getWidth(this),foreground.getHeight(this),foreground_data,0,foreground.getWidth(this)));//生成前景图象
……
}