关于图片处理的,这段java代码 怎么实现功能的?设计思想 算法思想 大家说说,我会再加分的 谢谢

来源:百度知道 编辑:UC知道 时间:2024/07/03 04:13:14
public BufferedImage emboss(BufferedImage src) {
int width = src.getWidth();
int height = src.getHeight();

BufferedImage dst;
dst = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

for (int i = 0; i < height; i++)
for (int j = 0; j < width; j++) {
int upperLeft = 0;
int lowerRight = 0;

if (i > 0 && j > 0)
upperLeft = src.getRGB(j - 1, i - 1);

if (i < height - 1 && j < width - 1)
lowerRight = src.getRGB(j + 1, i + 1);

int redDiff = ((lowerRight >> 16) & 255) - ((upperLeft >> 16) & 255);

int greenDiff = ((lowerRight >> 8) & 255) - ((upperLeft >> 8) & 255);

int blueDiff = (lowerRight & 255) - (upperLeft & 255);

int diff = redDiff;

按冒泡排序思想,有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;i<a.length;i++){ //a.length 数组的长度
for(int j=i+1;j<a.length;j++){
if(a[j]>a[i]){ // 进行交换
c=a[j];
a[j]=a[i];
a[i]=c;
}
}
System.out.println(a[i]);
}
}

int width = src.getWidth();
int height = src.getHeight();

BufferedImage dst;
dst = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

for (int i = 0; i < height; i++)