?? image縮小.java
字號:
import javax.imageio.*;//ImageIO
import java.awt.image.BufferedImage;//BufferedImage
import java.io.*; //File IOException
public class Image縮小 {
public static void main(String[] args) throws Exception{
RgbHsv bo = new RgbHsv();
BufferedImage abc = bo.返回BufferedImage對象("D:/Backup/我的文檔/My Pictures/power5.jpg");
//這兩種格式都可以獲得正確結(jié)果
int srcw = abc.getWidth();// 原圖像的寬度 srcw = 1024
int srch = abc.getHeight(null);// 原圖像的高度 srch = 768
BufferedImage uut = new BufferedImage(srcw / 2, srch / 2, 8) ;//依次構(gòu)造生成的圖像的寬度、高度、每一個(gè)RGB的位數(shù)
for(int i = 0; i < srcw -1; i += 2)
for(int j = 0; j < srch - 1; j += 2){
int rgb00 = abc.getRGB(i, j);
int rgb01 = abc.getRGB(i, j + 1);
int rgb10 = abc.getRGB(i + 1, j);
int rgb11 = abc.getRGB(i + 1, j + 1);
int r00 = (rgb00 & 0xff0000) >> 16;//獲取r
int g00 = (rgb00 & 0x00ff00) >> 8;//獲取b
int b00 = (rgb00 & 0x0000ff);//獲取g
int r01 = (rgb01 & 0xff0000) >> 16;//獲取r
int g01 = (rgb01 & 0x00ff00) >> 8;//獲取b
int b01 = (rgb01 & 0x0000ff);//獲取g
int r10 = (rgb10 & 0xff0000) >> 16;//獲取r
int g10 = (rgb10 & 0x00ff00) >> 8;//獲取b
int b10 = (rgb10 & 0x0000ff);//獲取g
int r11 = (rgb11 & 0xff0000) >> 16;//獲取r
int g11 = (rgb11 & 0x00ff00) >> 8;//獲取b
int b11 = (rgb11 & 0x0000ff);//獲取g
int r = (r00 + r01 + r10 + r11) / 4;
int g = (g00 + g01 + g10 + g11) / 4;
int b = (b00 + b01 + b10 + b11) / 4;
int rgb = (r << 16) + (g << 8) + b;
uut.setRGB(i / 2, j / 2, rgb);
}
ImageIO.write(uut, "jpg",new File("D:/Backup/我的文檔/My Pictures/power5s圖像縮小.jpg"));
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -