图片合并

package com.overseas;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

/**
 * @version 1.0
 * @since 2009-07-02
 * @author springmvc2006@sina.com
 *
 */
public class AggregaPicture {

 private static int alpha = 1000; // 0, 100, 1000, 10000

 private static String pictureType = "png"; // png, jpg

 public static void main(String[] args) throws Exception {

  File workFile = new File("d:/img/work");
  builderPicture(new File(workFile, "1.jpg"), "d:/img/work/", 20, 20);
  transferSize(workFile, 600, 600); // 要转的图片路径
  AggregaPicture aggregaPicture = new AggregaPicture();
  File temp = new File(workFile.getParent() + "/temp"); // 临时文件


  aggregaPicture.task(new File("d:/img/aggregaPictureFileName20@20."
    + pictureType), temp, 20, 20);
/*  aggregaPicture.task(new File("d:/img/aggregaPictureFileName3@3."
    + pictureType), temp, 3, 3);
  aggregaPicture.task(new File("d:/img/aggregaPictureFileName9@1."
    + pictureType), temp, 9, 1);
  aggregaPicture.task(new File("d:/img/aggregaPictureFileName4@2."
    + pictureType), temp, 4, 2);
  aggregaPicture.task(new File("d:/img/aggregaPictureFileName3@2."
    + pictureType), temp, 3, 2);
  aggregaPicture.deleteImage(temp);*/

 }

 public static void builderPicture(File file, String newPath, int colNum, int rowNum) {
  for(int i=0; i<colNum*rowNum; i++){
   copy(file, newPath+i+"."+pictureType);
  }
 }

 /**
  * @param width
  * @param height
  */
 public void task(File aggregaPictureFileName, File file, int rowNum,
   int colNum) throws Exception {
  if (!file.exists()) {
   throw new FileNotFoundException();
  }

  File[] files = file.listFiles();

  if (files.length < rowNum * colNum) {
   throw new ArrayIndexOutOfBoundsException();
  }

  ImageIcon rowResultImage = null;
  ImageIcon resultImage = null;
  String imageOneName = null;
  String imageTwoName = null;

  if (colNum > 1) {
   rowResultImage = mergeRow(files, 1, colNum);
   resultImage = rowResultImage;
   for (int i = 2; (i <= rowNum) && (colNum > 1); i++) {
    rowResultImage = mergeRow(files, i, colNum);
    resultImage = mergeCol(resultImage, rowResultImage);
   }
  } else if (colNum == 1) {
   ImageIcon imageIconOne = null;
   ImageIcon imageIconTwo = null;
   imageOneName = files[0].getAbsolutePath();
   imageTwoName = files[1].getAbsolutePath();
   imageIconOne = new ImageIcon(imageOneName);
   imageIconTwo = new ImageIcon(imageTwoName);

   rowResultImage = mergeVertical(imageIconOne, imageIconTwo);
   resultImage = rowResultImage;
   for (int i = 2; i < rowNum; i++) {
    System.out.println("col =" + files[i].getAbsolutePath());
    rowResultImage = new ImageIcon(files[i].getAbsolutePath());
    resultImage = mergeCol(resultImage, rowResultImage);
   }
  }

  saveAggregaPictureFile(resultImage, aggregaPictureFileName);
 }

 public ImageIcon mergeRow(File[] files, int rowNum, int colNum)
   throws Exception {

  ImageIcon imageIconOne = null;
  ImageIcon imageIconTwo = null;
  ImageIcon rowResultImage = null;

  String imageOneName = null;
  String imageTwoName = null;

  imageOneName = files[colNum * (rowNum - 1)].getAbsolutePath();

  System.out.println("rowNum " + rowNum);
  System.out.println(imageOneName);
  imageTwoName = files[colNum * (rowNum - 1) + 1].getAbsolutePath();
  System.out.println(imageTwoName);

  imageIconOne = new ImageIcon(imageOneName);
  imageIconTwo = new ImageIcon(imageTwoName);

  rowResultImage = mergeHorizontal(imageIconOne, imageIconTwo);

  for (int i = 2; i < colNum; i++) {
   imageOneName = files[colNum * (rowNum - 1) + i].getAbsolutePath();
   System.out.println(imageOneName);
   imageIconOne = new ImageIcon(imageOneName);
   rowResultImage = mergeHorizontal(rowResultImage, imageIconOne);
  }

  return rowResultImage;

 }

 public ImageIcon mergeCol(ImageIcon imageOne, ImageIcon imageTwo)
   throws Exception {
  return mergeVertical(imageOne, imageTwo);
 }

 public ImageIcon mergeHorizontal(ImageIcon imageOne, ImageIcon imageTwo)
   throws Exception {
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

  BufferedImage bufferedImage = setAlpha(imageOne);
  int widthOne = bufferedImage.getWidth();
  int heightOne = bufferedImage.getHeight();
  int[] imageArrayOne = new int[widthOne * heightOne];
  imageArrayOne = bufferedImage.getRGB(0, 0, widthOne, heightOne,
    imageArrayOne, 0, widthOne);

  BufferedImage bufferedImageTwo = setAlpha(imageTwo);
  int widthTwo = bufferedImageTwo.getWidth();
  int heightTwo = bufferedImageTwo.getHeight();
  int[] imageArrayTwo = new int[widthTwo * heightTwo];
  imageArrayTwo = bufferedImageTwo.getRGB(0, 0, widthTwo, heightTwo,
    imageArrayTwo, 0, widthTwo);

  // int smallHeightSize = heightOne > heightTwo ? heightTwo : heightOne;

  // 生成新图片
  BufferedImage imageNew = new BufferedImage(widthOne + widthTwo,
    heightOne, BufferedImage.TYPE_INT_RGB);
  imageNew.setRGB(0, 0, widthOne, heightOne, imageArrayOne, 0, widthOne);// 设置左半部分的RGB
  imageNew.setRGB(widthOne, 0, widthTwo, heightTwo, imageArrayTwo, 0,
    widthTwo);
  ImageIO.write(imageNew, pictureType, byteArrayOutputStream);// 写图片

  File file = new File("d:/img/mergeHorizontal");
  if (!file.exists()) {
   file.mkdirs();
  }
  ImageIO.write(imageNew, pictureType, new File("d:/img/mergeHorizontal/"
    + getSystemDate() + "." + pictureType));

  ImageIcon tempIcon = new ImageIcon(byteArrayOutputStream.toByteArray());
  return tempIcon;
 }

 public ImageIcon mergeVertical(ImageIcon imageOne, ImageIcon imageTwo)
   throws Exception {
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

  BufferedImage bufferedImage = setAlpha(imageOne);
  int widthOne = bufferedImage.getWidth();
  int heightOne = bufferedImage.getHeight();


  BufferedImage bufferedImageTwo = setAlpha(imageTwo);
  int widthTwo = bufferedImageTwo.getWidth();
  int heightTwo = bufferedImageTwo.getHeight();
  int[] imageArrayTwo = new int[widthTwo * heightTwo];
  

  // 生成新图片
  BufferedImage imageNew = new BufferedImage(widthOne, heightOne
    + heightTwo, BufferedImage.TYPE_INT_RGB);
  
  
  imageArrayTwo = bufferedImageTwo.getRGB(0, 0, widthTwo, heightTwo,
    imageArrayTwo, 0, widthTwo);
  imageNew.setRGB(0, heightOne, widthTwo, heightTwo, imageArrayTwo, 0,
    widthTwo);
  imageArrayTwo = null;
  bufferedImageTwo = null;
  
  
  int[] imageArrayOne = new int[widthOne * heightOne];
  imageArrayOne = bufferedImage.getRGB(0, 0, widthOne, heightOne,
    imageArrayOne, 0, widthOne);
  imageNew.setRGB(0, 0, widthOne, heightOne, imageArrayOne, 0, widthOne);
  imageArrayOne = null;
  bufferedImage = null;


  // imageNew.setRGB(width,0,width,height,imageArrayTwo,0,width);

  ImageIO.write(imageNew, pictureType, byteArrayOutputStream);// 写图片

  File file = new File("d:/img/mergeVertical");
  if (!file.exists()) {
   file.mkdirs();
  }
  ImageIO.write(imageNew, pictureType, new File("d:/img/mergeVertical/"
    + getSystemDate() + "." + pictureType));
  ImageIcon tempIcon = new ImageIcon(byteArrayOutputStream.toByteArray());
  return tempIcon;
 }

 private BufferedImage setAlpha(ImageIcon imageIcon) {
  BufferedImage bufferedImage = new BufferedImage(imageIcon
    .getIconWidth(), imageIcon.getIconHeight(),
    BufferedImage.TYPE_4BYTE_ABGR);
  try {

   Graphics2D g2D = (Graphics2D) bufferedImage.getGraphics();
   g2D.drawImage(imageIcon.getImage(), 0, 0, imageIcon
     .getImageObserver());
   // int alpha = 100;
   for (int j1 = bufferedImage.getMinY(); j1 < bufferedImage
     .getHeight(); j1++) {
    for (int j2 = bufferedImage.getMinX(); j2 < bufferedImage
      .getWidth(); j2++) {
     int rgb = bufferedImage.getRGB(j2, j1);
     int R = (rgb & 0xff0000) >> 16;
     int G = (rgb & 0xff00) >> 8;
     int B = (rgb & 0xff);

     rgb = ((alpha + 1) << 24) | (rgb & 0x00ffffff);

     bufferedImage.setRGB(j2, j1, rgb);
    }
   }
   g2D.dispose();
  } catch (Exception e) {
   e.printStackTrace();
  }

  return bufferedImage;

 }

 public void saveAggregaPictureFile(ImageIcon imageIcon,
   File aggregaPictureFileName) throws Exception {
  BufferedImage bufferedImage = new BufferedImage(imageIcon
    .getIconWidth(), imageIcon.getIconHeight(),
    BufferedImage.TYPE_4BYTE_ABGR);
  Graphics2D g2D = (Graphics2D) bufferedImage.getGraphics();
  g2D.drawImage(imageIcon.getImage(), 0, 0, imageIcon.getImageObserver());
  // 循环每一个像素点,改变像素点的Alpha值
  // int alpha = 100;
  for (int j1 = bufferedImage.getMinY(); j1 < bufferedImage.getHeight(); j1++) {
   for (int j2 = bufferedImage.getMinX(); j2 < bufferedImage
     .getWidth(); j2++) {
    int rgb = bufferedImage.getRGB(j2, j1);
    int R = (rgb & 0xff0000) >> 16;
    int G = (rgb & 0xff00) >> 8;
    int B = (rgb & 0xff);

    //rgb = ((alpha + 1) << 24) | (rgb & 0x00ffffff);

    bufferedImage.setRGB(j2, j1, rgb);

   }
  }
  g2D.drawImage(bufferedImage, 0, 0, imageIcon.getImageObserver());

  // 生成图片为PNG

  ImageIO.write(bufferedImage, pictureType, aggregaPictureFileName);
  g2D.dispose();
 }

 public static void transferSize(File imgDir, int width, int heigth)
   throws Exception {
  if (!imgDir.exists()) {
   throw new FileNotFoundException();
  }

  String tempDir = imgDir.getParent() + "/temp/";
  File file = new File(tempDir);
  if (!file.exists()) {
   file.mkdirs();
  }

  File[] imgFiles = imgDir.listFiles();

  for (int i = 0; i < imgFiles.length; i++) {
   if (imgFiles[i].isFile()) {
    ScaleImage is = new ScaleImage();
    try {
     System.out.println(imgFiles[i].getAbsolutePath());
     is.saveImageAsJpg(imgFiles[i].getAbsolutePath(), tempDir
       + imgFiles[i].getName(), width, heigth);
    } catch (Exception e) {
     e.printStackTrace();
    }

   }
  }
 }

 public static void copy(String oldPath, String newPath) {
  File oldfile = new File(oldPath);
  copy(oldfile, newPath);
 }

 public static void copy(File oldfile, String newPath) {
  InputStream inStream = null;
  FileOutputStream fs = null;
  try {
   int bytesum = 0;
   int byteread = 0;
   if (oldfile.exists()) {
    inStream = new FileInputStream(oldfile);
    fs = new FileOutputStream(newPath);
    byte[] buffer = new byte[1024];
    while ((byteread = inStream.read(buffer)) != -1) {
     bytesum += byteread;
     fs.write(buffer, 0, byteread);
    }
    inStream.close();
    fs.close();
   }
  } catch (Exception e) {
   System.out.println("error  ");
   e.printStackTrace();
  }finally{
   if(inStream != null){
    try {
     inStream.close();
     inStream = null;
    } catch (IOException e) {
     e.printStackTrace();
    }
   }
   
   if(fs != null){
    try {
     fs.close();
     fs = null;
    } catch (IOException e) {
     e.printStackTrace();
    }
   }
  }
 }

 public void deleteImage(File temp) {
  if (temp.exists()) {

   File[] tempImages = temp.listFiles();
   for (int i = 0; i < tempImages.length; i++) {
    tempImages[i].delete();
   }
  }

 }

 public static String getSystemDate() {
  Calendar cal = Calendar.getInstance();
  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
  String mDateTime = formatter.format(cal.getTime());
  return mDateTime;
 }

}

 

package com.overseas;

import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

/**
 * springmvc2006@sina.com
 *
 */
public class ScaleImage {
 
 
 private int width;  
  
    private int height;  
 
    private int scaleWidth;  
 
    double support = (double) 3.0;  
 
    double PI = (double) 3.14159265358978;  
 
    double[] contrib;  
 
    double[] normContrib;  
 
    double[] tmpContrib;  
 
    int startContrib, stopContrib;  
 
    int nDots;  
 
    int nHalfDots;  
 

    public static void main(String[] args) {  
        ScaleImage is = new ScaleImage();  
        try {  
            is.saveImageAsJpg("d:/img/temp/3.jpg", "d:/img/temp/3.bak.jpg", 200, 200);  
        } catch (Exception e) {  
            // TODO Auto-generated catch block  
            e.printStackTrace();  
        }  
    }  
 
    // fromFileStr原图片地址,saveToFileStr生成缩略图地址,formatWideth生成图片宽度,formatHeight高度  
    public void saveImageAsJpg(String fromFileStr, String saveToFileStr,  
            int formatWideth, int formatHeight) throws Exception {  
        BufferedImage srcImage;  
        File saveFile = new File(saveToFileStr);  
        File fromFile = new File(fromFileStr);  
        srcImage = javax.imageio.ImageIO.read(fromFile); // construct image  
        int imageWideth = srcImage.getWidth(null);  
        int imageHeight = srcImage.getHeight(null);  
        int changeToWideth = 0;  
        int changeToHeight = 0;  
        if (imageWideth > 0 && imageHeight > 0) {  
            // flag=true;  
            if (imageWideth / imageHeight >= formatWideth / formatHeight) {  
                if (imageWideth > formatWideth) {  
                    changeToWideth = formatWideth;  
                    changeToHeight = (imageHeight * formatWideth) / imageWideth;  
                } else {  
                    changeToWideth = imageWideth;  
                    changeToHeight = imageHeight;  
                }  
            } else {  
                if (imageHeight > formatHeight) {  
                    changeToHeight = formatHeight;  
                    changeToWideth = (imageWideth * formatHeight) / imageHeight;  
                } else {  
                    changeToWideth = imageWideth;  
                    changeToHeight = imageHeight;  
                }  
            }  
        }  
 
        srcImage = imageZoomOut(srcImage, changeToWideth, changeToHeight);  
        ImageIO.write(srcImage, "JPEG", saveFile);  
    }  
 
    public BufferedImage imageZoomOut(BufferedImage srcBufferImage, int w, int h) {  
        width = srcBufferImage.getWidth();  
        height = srcBufferImage.getHeight();  
        scaleWidth = w;  
 
        if (DetermineResultSize(w, h) == 1) {  
            return srcBufferImage;  
        }  
        CalContrib();  
        BufferedImage pbOut = HorizontalFiltering(srcBufferImage, w);  
        BufferedImage pbFinalOut = VerticalFiltering(pbOut, h);  
        return pbFinalOut;  
    }  
 
    /** *//** 
     * 决定图像尺寸 
     */ 
    private int DetermineResultSize(int w, int h) {  
        double scaleH, scaleV;  
        scaleH = (double) w / (double) width;  
        scaleV = (double) h / (double) height;  
        // 需要判断一下scaleH,scaleV,不做放大操作  
        if (scaleH >= 1.0 && scaleV >= 1.0) {  
            return 1;  
        }  
        return 0;  
 
    } // end of DetermineResultSize()  
 
    private double Lanczos(int i, int inWidth, int outWidth, double Support) {  
        double x;  
 
        x = (double) i * (double) outWidth / (double) inWidth;  
 
        return Math.sin(x * PI) / (x * PI) * Math.sin(x * PI / Support)  
                / (x * PI / Support);  
 
    }  
 
    private void CalContrib() {  
        nHalfDots = (int) ((double) width * support / (double) scaleWidth);  
        nDots = nHalfDots * 2 + 1;  
        try {  
            contrib = new double[nDots];  
            normContrib = new double[nDots];  
            tmpContrib = new double[nDots];  
        } catch (Exception e) {  
            System.out.println("init   contrib,normContrib,tmpContrib" + e);  
        }  
 
        int center = nHalfDots;  
        contrib[center] = 1.0;  
 
        double weight = 0.0;  
        int i = 0;  
        for (i = 1; i <= center; i++) {  
            contrib[center + i] = Lanczos(i, width, scaleWidth, support);  
            weight += contrib[center + i];  
        }  
 
        for (i = center - 1; i >= 0; i--) {  
            contrib[i] = contrib[center * 2 - i];  
        }  
 
        weight = weight * 2 + 1.0;  
 
        for (i = 0; i <= center; i++) {  
            normContrib[i] = contrib[i] / weight;  
        }  
 
        for (i = center + 1; i < nDots; i++) {  
            normContrib[i] = normContrib[center * 2 - i];  
        }  
    } // end of CalContrib()  
 
    // 处理边缘  
    private void CalTempContrib(int start, int stop) {  
        double weight = 0;  
 
        int i = 0;  
        for (i = start; i <= stop; i++) {  
            weight += contrib[i];  
        }  
 
        for (i = start; i <= stop; i++) {  
            tmpContrib[i] = contrib[i] / weight;  
        }  
 
    } // end of CalTempContrib()  
 
    private int GetRedValue(int rgbValue) {  
        int temp = rgbValue & 0x00ff0000;  
        return temp >> 16;  
    }  
 
    private int GetGreenValue(int rgbValue) {  
        int temp = rgbValue & 0x0000ff00;  
        return temp >> 8;  
    }  
 
    private int GetBlueValue(int rgbValue) {  
        return rgbValue & 0x000000ff;  
    }  
 
    private int ComRGB(int redValue, int greenValue, int blueValue) {  
 
        return (redValue << 16) + (greenValue << 8) + blueValue;  
    }  
 
    // 行水平滤波  
    private int HorizontalFilter(BufferedImage bufImg, int startX, int stopX,  
            int start, int stop, int y, double[] pContrib) {  
        double valueRed = 0.0;  
        double valueGreen = 0.0;  
        double valueBlue = 0.0;  
        int valueRGB = 0;  
        int i, j;  
 
        for (i = startX, j = start; i <= stopX; i++, j++) {  
            valueRGB = bufImg.getRGB(i, y);  
 
            valueRed += GetRedValue(valueRGB) * pContrib[j];  
            valueGreen += GetGreenValue(valueRGB) * pContrib[j];  
            valueBlue += GetBlueValue(valueRGB) * pContrib[j];  
        }  
 
        valueRGB = ComRGB(Clip((int) valueRed), Clip((int) valueGreen),  
                Clip((int) valueBlue));  
        return valueRGB;  
 
    } // end of HorizontalFilter()  
 
    // 图片水平滤波  
    private BufferedImage HorizontalFiltering(BufferedImage bufImage, int iOutW) {  
        int dwInW = bufImage.getWidth();  
        int dwInH = bufImage.getHeight();  
        int value = 0;  
        BufferedImage pbOut = new BufferedImage(iOutW, dwInH,  
                BufferedImage.TYPE_INT_RGB);  
 
        for (int x = 0; x < iOutW; x++) {  
 
            int startX;  
            int start;  
            int X = (int) (((double) x) * ((double) dwInW) / ((double) iOutW) + 0.5);  
            int y = 0;  
 
            startX = X - nHalfDots;  
            if (startX < 0) {  
                startX = 0;  
                start = nHalfDots - X;  
            } else {  
                start = 0;  
            }  
 
            int stop;  
            int stopX = X + nHalfDots;  
            if (stopX > (dwInW - 1)) {  
                stopX = dwInW - 1;  
                stop = nHalfDots + (dwInW - 1 - X);  
            } else {  
                stop = nHalfDots * 2;  
            }  
 
            if (start > 0 || stop < nDots - 1) {  
                CalTempContrib(start, stop);  
                for (y = 0; y < dwInH; y++) {  
                    value = HorizontalFilter(bufImage, startX, stopX, start,  
                            stop, y, tmpContrib);  
                    pbOut.setRGB(x, y, value);  
                }  
            } else {  
                for (y = 0; y < dwInH; y++) {  
                    value = HorizontalFilter(bufImage, startX, stopX, start,  
                            stop, y, normContrib);  
                    pbOut.setRGB(x, y, value);  
                }  
            }  
        }  
 
        return pbOut;  
 
    } // end of HorizontalFiltering()  
 
    private int VerticalFilter(BufferedImage pbInImage, int startY, int stopY,  
            int start, int stop, int x, double[] pContrib) {  
        double valueRed = 0.0;  
        double valueGreen = 0.0;  
        double valueBlue = 0.0;  
        int valueRGB = 0;  
        int i, j;  
 
        for (i = startY, j = start; i <= stopY; i++, j++) {  
            valueRGB = pbInImage.getRGB(x, i);  
 
            valueRed += GetRedValue(valueRGB) * pContrib[j];  
            valueGreen += GetGreenValue(valueRGB) * pContrib[j];  
            valueBlue += GetBlueValue(valueRGB) * pContrib[j];  
            // System.out.println(valueRed+"->"+Clip((int)valueRed)+"<-");  
            //     
            // System.out.println(valueGreen+"->"+Clip((int)valueGreen)+"<-");  
            // System.out.println(valueBlue+"->"+Clip((int)valueBlue)+"<-"+"-->");  
        }  
 
        valueRGB = ComRGB(Clip((int) valueRed), Clip((int) valueGreen),  
                Clip((int) valueBlue));  
        // System.out.println(valueRGB);  
        return valueRGB;  
 
    } // end of VerticalFilter()  
 
    private BufferedImage VerticalFiltering(BufferedImage pbImage, int iOutH) {  
        int iW = pbImage.getWidth();  
        int iH = pbImage.getHeight();  
        int value = 0;  
        BufferedImage pbOut = new BufferedImage(iW, iOutH,  
                BufferedImage.TYPE_INT_RGB);  
 
        for (int y = 0; y < iOutH; y++) {  
 
            int startY;  
            int start;  
            int Y = (int) (((double) y) * ((double) iH) / ((double) iOutH) + 0.5);  
 
            startY = Y - nHalfDots;  
            if (startY < 0) {  
                startY = 0;  
                start = nHalfDots - Y;  
            } else {  
                start = 0;  
            }  
 
            int stop;  
            int stopY = Y + nHalfDots;  
            if (stopY > (int) (iH - 1)) {  
                stopY = iH - 1;  
                stop = nHalfDots + (iH - 1 - Y);  
            } else {  
                stop = nHalfDots * 2;  
            }  
 
            if (start > 0 || stop < nDots - 1) {  
                CalTempContrib(start, stop);  
                for (int x = 0; x < iW; x++) {  
                    value = VerticalFilter(pbImage, startY, stopY, start, stop,  
                            x, tmpContrib);  
                    pbOut.setRGB(x, y, value);  
                }  
            } else {  
                for (int x = 0; x < iW; x++) {  
                    value = VerticalFilter(pbImage, startY, stopY, start, stop,  
                            x, normContrib);  
                    pbOut.setRGB(x, y, value);  
                }  
            }  
 
        }  
 
        return pbOut;  
 
    } // end of VerticalFiltering()  
 
    int Clip(int x) {  
        if (x < 0)  
            return 0;  
        if (x > 255)  
            return 255;  
        return x;  
    }  

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值