BufferedImage類有一個getSubimage()方法,以下來自API
創(chuàng)新互聯(lián)是一家專業(yè)提供麻山企業(yè)網(wǎng)站建設(shè),專注與網(wǎng)站設(shè)計(jì)制作、做網(wǎng)站、HTML5、小程序制作等業(yè)務(wù)。10年已為麻山眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站設(shè)計(jì)公司優(yōu)惠進(jìn)行中。
public BufferedImage getSubimage(int x,
int y,
int w,
int h)
返回由指定矩形區(qū)域定義的子圖像。返回的 BufferedImage 與源圖像共享相同的數(shù)據(jù)數(shù)組。
參數(shù):
x - 指定矩形區(qū)域左上角的 X 坐標(biāo)
y - 指定矩形區(qū)域左上角的 Y 坐標(biāo)
w - 指定矩形區(qū)域的寬度
h - 指定矩形區(qū)域的高度
返回:
BufferedImage,它是此 BufferedImage 的子圖像。
拋出:
RasterFormatException - 如果指定區(qū)域不包含在此 BufferedImage 中
public BufferedImage getSubimage(int x,
int y,
int w,
int h)返回由指定矩形區(qū)域定義的子圖像。返回的 BufferedImage 與源圖像共享相同的數(shù)據(jù)數(shù)組。
參數(shù):
x - 指定矩形區(qū)域左上角的 X 坐標(biāo)
y - 指定矩形區(qū)域左上角的 Y 坐標(biāo)
w - 指定矩形區(qū)域的寬度
h - 指定矩形區(qū)域的高度
你先把分塊的坐標(biāo)弄好,在拿這個方法去拿沒塊的圖就是了。
怎么會無法呢。java支持圖片格式中最好的就是png,別的圖片可以不支持,png是默認(rèn)支持的。用ARGB色彩模型直接對png操作即可,
import?java.awt.image.BufferedImage;
import?java.io.File;
import?java.io.IOException;
import?javax.imageio.ImageIO;
public?class?Test?{
static?public?void?main(String?參數(shù)[]){
try{
BufferedImage?img=ImageIO.read(new?File("test.png"));
int?half_w=img.getWidth()/2;
int?rgb[]=new?int[half_w*img.getHeight()];
img.getRGB(0,?0,?half_w,?img.getHeight(),?rgb,?0,?half_w);
BufferedImage?img_half=new?BufferedImage(half_w,?img.getHeight(),?BufferedImage.TYPE_INT_ARGB);
img_half.setRGB(0,?0,half_w,img.getHeight(),?rgb,0,half_w);
//保存到新文件half.png里面
ImageIO.write(img_half,"PNG",new?File("half.png"));
}catch?(IOException?e){
e.printStackTrace();
}
}
}
======
得到half.png簽名圖的左半邊,保留了透明的背景。
這已經(jīng)只有5-6行,拋磚引玉,用raster可能代碼更簡..
網(wǎng)站題目:圖像分割代碼java 圖像分割定義
轉(zhuǎn)載注明:http://chinadenli.net/article22/hpiscc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、網(wǎng)站制作、關(guān)鍵詞優(yōu)化、定制網(wǎng)站、網(wǎng)站營銷、企業(yè)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)