
正文
java图片处理底层代码 java 图片处理
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
怎么用java代码模拟一张图片
用java代码模拟一张图片可以这样操作java图片处理底层代码:1.创建BufferedImage类
2.根据BufferedImage类得到一个Graphics2D对象
3.根据Graphics2D对象进行逻辑操作
4.处理绘图
5.将绘制好java图片处理底层代码的图片写入到图片
相关问答
Q1: 关于图片处理的,这段java代码 怎么实现功能的?设计思想 算法思想 大家说说,我会再加分的 谢谢
按冒泡排序思想,有8颗豆子(大小不一)放在8袋子里, 从第1个袋了拿出豆子,与第2个袋子里的豆子相比较,如果第2个袋子里豆子比第1个袋子的豆子大,就把第2个袋子里的豆子放入第1个袋子,把第1个袋子的豆子放入第2个袋子。然后,第1个袋子继续和第3个袋子比较。如果第2袋子的豆子不会比第1个袋子的大,就和第3个袋子比较,这样一一个下直到和所有的袋子比较过。之后第2个袋子也与第2个袋子以后的相比较过.......!
另外还要用到交换的方法:
代码主要是用循环嵌套:
public class NewMain {
public static void main(String[] args) {
// TODO code application logic here
int a[]={1,5,8,11,16,30,40,50,199};//定义一个数组,也可写成 int[] a={1,5,8,11,16,30,40,50,199};
int c;//用于交换用的
for(int i=0;ia.length;i++){ //a.length 数组的长度
for(int j=i+1;ja.length;j++){
if(a[j]a[i]){ // 进行交换
c=a[j];
a[j]=a[i];
a[i]=c;
}
}
System.out.println(a[i]);
}
}
Q2: java适合做图像处理吗?
Java图像处理技巧四则
下面代码中用到的sourceImage是一个已经存在的Image对象
图像剪切
对于一个已经存在的Image对象java图片处理底层代码,要得到它的一个局部图像java图片处理底层代码,可以使用下面的步骤java图片处理底层代码:
//import java.awt.*;
//import java.awt.image.*;
Image croppedImage;
ImageFilter cropFilter;
CropFilter =new CropImageFilter(25,30,75,75); //四个参数分别为图像起点坐标和宽高,即CropImageFilter(int x,int y,int width,int height),详细情况请参考API
CroppedImage= Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(sourceImage.getSource(),cropFilter));
如果是在Component的子类中使用,可以将上面的Toolkit.getDefaultToolkit().去掉。FilteredImageSource是一个ImageProducer对象。
图像缩放
对于一个已经存在的Image对象,得到它的一个缩放的Image对象可以使用Image的getScaledInstance方法java图片处理底层代码:
Image scaledImage=sourceImage. getScaledInstance(100,100, Image.SCALE_DEFAULT); //得到一个100X100的图像
Image doubledImage=sourceImage. getScaledInstance(sourceImage.getWidth(this)*2,sourceImage.getHeight(this)*2, Image.SCALE_DEFAULT); //得到一个放大两倍的图像,这个程序一般在一个swing的组件中使用,而类Jcomponent实现java图片处理底层代码了图像观察者接口ImageObserver,所有可以使用this。
//其它情况请参考API
灰度变换
下面的程序使用三种方法对一个彩色图像进行灰度变换,变换的效果都不一样。一般而言,灰度变换的算法是将象素的三个颜色分量使用R*0.3+G*0.59+ B*0.11得到灰度值,然后将之赋值给红绿蓝,这样颜色取得的效果就是灰度的。另一种就是取红绿蓝三色中的最大值作为灰度值。java核心包也有一种算法,但是没有看源代码,不知道具体算法是什么样的,效果和上述不同。
/* GrayFilter.java*/
/*@author:cherami */
/*email:cherami@163.net*/
import java.awt.image.*;
public class GrayFilter extends RGBImageFilter {
int modelStyle;
public GrayFilter() {
modelStyle=GrayModel.CS_MAX;
canFilterIndexColorModel=true;
}
public GrayFilter(int style) {
modelStyle=style;
canFilterIndexColorModel=true;
}
public void setColorModel(ColorModel cm) {
if (modelStyle==GrayModel
else if (modelStyle==GrayModel
}
public int filterRGB(int x,int y,int pixel) {
return pixel;
}
}
/* GrayModel.java*/
/*@author:cherami */
/*email:cherami@163.net*/
import java.awt.image.*;
public class GrayModel extends ColorModel {
public static final int CS_MAX=0;
public static final int CS_FLOAT=1;
ColorModel sourceModel;
int modelStyle;
public GrayModel(ColorModel sourceModel) {
super(sourceModel.getPixelSize());
this.sourceModel=sourceModel;
modelStyle=0;
}
public GrayModel(ColorModel sourceModel,int style) {
super(sourceModel.getPixelSize());
this.sourceModel=sourceModel;
modelStyle=style;
}
public void setGrayStyle(int style) {
modelStyle=style;
}
protected int getGrayLevel(int pixel) {
if (modelStyle==CS_MAX) {
return Math.max(sourceModel.getRed(pixel),Math.max(sourceModel.getGreen(pixel),sourceModel.getBlue(pixel)));
}
else if (modelStyle==CS_FLOAT){
return (int)(sourceModel.getRed(pixel)*0.3+sourceModel.getGreen(pixel)*0.59+sourceModel.getBlue(pixel)*0.11);
}
else {
return 0;
}
}
public int getAlpha(int pixel) {
return sourceModel.getAlpha(pixel);
}
public int getRed(int pixel) {
return getGrayLevel(pixel);
}
public int getGreen(int pixel) {
return getGrayLevel(pixel);
}
public int getBlue(int pixel) {
return getGrayLevel(pixel);
}
public int getRGB(int pixel) {
int gray=getGrayLevel(pixel);
return (getAlpha(pixel)24)+(gray16)+(gray8)+gray;
}
}
如果你有自己的算法或者想取得特殊的效果,你可以修改类GrayModel的方法getGrayLevel()。
色彩变换
根据上面的原理,我们也可以实现色彩变换,这样的效果就很多了。下面是一个反转变换的例子:
/* ReverseColorModel.java*/
/*@author:cherami */
/*email:cherami@163.net*/
import java.awt.image.*;
public class ReverseColorModel extends ColorModel {
ColorModel sourceModel;
public ReverseColorModel(ColorModel sourceModel) {
super(sourceModel.getPixelSize());
this.sourceModel=sourceModel;
}
public int getAlpha(int pixel) {
return sourceModel.getAlpha(pixel);
}
public int getRed(int pixel) {
return ~sourceModel.getRed(pixel);
}
public int getGreen(int pixel) {
return ~sourceModel.getGreen(pixel);
}
public int getBlue(int pixel) {
return ~sourceModel.getBlue(pixel);
}
public int getRGB(int pixel) {
return (getAlpha(pixel)24)+(getRed(pixel)16)+(getGreen(pixel)8)+getBlue(pixel);
}
}
/* ReverseColorModel.java*/
/*@author:cherami */
/*email:cherami@163.net*/
import java.awt.image.*;
public class ReverseFilter extends RGBImageFilter {
public ReverseFilter() {
canFilterIndexColorModel=true;
}
public void setColorModel(ColorModel cm) {
substituteColorModel(cm,new ReverseColorModel(cm));
}
public int filterRGB(int x,int y,int pixel) {
return pixel;
}
}
要想取得自己的效果,需要修改ReverseColorModel.java中的三个方法,getRed、getGreen、getBlue。
下面是上面的效果的一个总的演示程序。
/*GrayImage.java*/
/*@author:cherami */
/*email:cherami@163.net*/
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
import java.awt.color.*;
public class GrayImage extends JFrame{
Image source,gray,gray3,clip,bigimg;
BufferedImage bimg,gray2;
GrayFilter filter,filter2;
ImageIcon ii;
ImageFilter cropFilter;
int iw,ih;
public GrayImage() {
ii=new ImageIcon(\"images/11.gif\");
source=ii.getImage();
iw=source.getWidth(this);
ih=source.getHeight(this);
filter=new GrayFilter();
filter2=new GrayFilter(GrayModel.CS_FLOAT);
gray=createImage(new FilteredImageSource(source.getSource(),filter));
gray3=createImage(new FilteredImageSource(source.getSource(),filter2));
cropFilter=new CropImageFilter(5,5,iw-5,ih-5);
clip=createImage(new FilteredImageSource(source.getSource(),cropFilter));
bigimg=source.getScaledInstance(iw*2,ih*2,Image.SCALE_DEFAULT);
MediaTracker mt=new MediaTracker(this);
mt.addImage(gray,0);
try {
mt.waitForAll();
} catch (Exception e) {
}
Q3: java 图片处理。如题。。
每次画图之前先用背景色填充一个框就可以啊
g2d.setColor(Color.white);//设背景色
g2d.fillRect(0,0,600,600);//填充整个窗口
Q4: java中绘制图片是如何将它置于底层
重写setFrame方法java图片处理底层代码,自己调整celljava图片处理底层代码的frame
- (void)setFrame:(CGRect)frame
{
// 更改x、宽度
frame.origin.x = kTableBorderWidth;
frame.size.width -= kTableBorderWidth * 2;
// 更改顶部间距、每个cell之间java图片处理底层代码的间距
frame.origin.y += kTableTopBorderWidth;
frame.size.height -= kTableViewCellMargin;
[super setFrame:frame];
}
Q5: java / jsp图片处理
首先java图片处理底层代码你先用javax.imageio.imageReader类将用户上传java图片处理底层代码的图片读取到内存中生成BufferImage对象java图片处理底层代码,此对象能够对图像像素矩阵进行操作java图片处理底层代码,
转换成黑白图片以及白色显示为透明状态都有常用的算法,其实就是操作图片的像素点
处理完后再通过imageWriter类将图片存为图片文件,在页面上用img标签显示就行java图片处理底层代码了
具体的函数方法去参考api
jdk 里面有对jepg 和 bmp格式图像读取的类
关于java图片处理底层代码和java 图片处理的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







