java圖片變成黑白代碼,java圖片變成黑白代碼了

JAVA按鈕setEnabled(false)掉 貼圖變黑白 不想這樣要怎么處理

目前創新互聯已為上千的企業提供了網站建設、域名、雅安服務器托管、網站托管、服務器租用、企業網站設計、鳳凰網站維護等服務,公司將堅持客戶導向、應用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協力一起成長,共同發展。

現在想到的辦法是

不用setEnabled

自己把他的監聽 給改了 達到和setEnabled的效果 點擊沒有用 但是圖片還是彩色的

試一下吧

java怎么實現將 bmp圖片黑底白字轉換為白底黑字?將白色設置為透明色,謝謝

代碼如下:

package?com.baidu.demo019;

import?java.awt.*;

import?java.awt.image.BufferedImage;

import?java.io.*;

import?javax.imageio.ImageIO;

import?javax.swing.*;

public?class?App?extends?JFrame?{

private?static?final?long?serialVersionUID?=?1L;

public?App()?{

this.setSize(500,?500);

this.setLocationRelativeTo(null);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Box?box?=?Box.createVerticalBox();

this.add(box);

//?源圖像路徑

String?imageFile?=?"images/demo019.bmp";

//?源圖像

BufferedImage?image1?=?getImage(imageFile);

JLabel?label1?=?new?JLabel(new?ImageIcon(image1));

JPanel?panel1?=?new?JPanel(new?BorderLayout());

panel1.add(label1);

box.add(panel1);

//?轉換后的圖像

Image?image2?=?translateImage(image1);

JLabel?label2?=?new?JLabel(new?ImageIcon(image2));

JPanel?panel2?=?new?JPanel(new?BorderLayout());

panel2.add(label2);

box.add(panel2);

}

BufferedImage?getImage(String?imageFile)?{

BufferedImage?image?=?null;

try?{

image?=?ImageIO.read(new?File(imageFile));

}?catch?(IOException?e)?{

e.printStackTrace();

}

return?image;

}

//?轉換圖像?黑底白字轉換為白底黑字,白色設置為透明色

private?Image?translateImage(BufferedImage?image)?{

int?width?=?image.getWidth();

int?height?=?image.getHeight();

BufferedImage?target?=?new?BufferedImage(width,?height,?BufferedImage.TYPE_INT_ARGB);

for?(int?i?=?0;?i??width;?i++)?{

for?(int?j?=?0;?j??height;?j++)?{

int?val?=?image.getRGB(i,?j);

int?red?=?(val??16)??0xff;

int?green?=?(val??8)??0xff;

int?blue?=?val???0xff;

red?=?255?-?red;

green?=?255?-?green;

blue?=?255?-?blue;

int?alpha?=?0xff;

if?((red?+?green?+?blue)?/?3?=?0xff)?{

alpha?=?0x00;

}

int?pixel?=?(alpha??24)?|?(red??16)?|?(green??8)?|?(blue);

target.setRGB(i,?j,?pixel);

}

}

return?target;

}

public?static?void?main(String[]?args)?{

new?App().setVisible(true);

}

}

運行結果:

java中改變一副彩色照片的顏色,使之成為黑白照片,如何添加圖片?

//功能已實現

//沒什么好注釋的,都是API,請君自行查看

import java.awt.Image;

import java.awt.color.ColorSpace;

import java.awt.image.BufferedImage;

import java.awt.image.ColorConvertOp;

import java.io.File;

import java.io.FileOutputStream;

import java.io.IOException;

import javax.imageio.ImageIO;

import com.sun.image.codec.jpeg.JPEGCodec;import com.sun.image.codec.jpeg.JPEGImageEncoder;

public class ImageUtil {

public static void main(String[] args) {

File file=new File("C:\\Documents and Settings\\Administrator\\桌面\\cd.jpg");

changeImge(file);

}

/**

* * 轉換圖片 * *

*/

public static void changeImge(File img) {

try {

Image image = ImageIO.read(img);

int srcH = image.getHeight(null);

int srcW = image.getWidth(null);

BufferedImage bufferedImage = new BufferedImage(srcW, srcH,BufferedImage.TYPE_3BYTE_BGR);

bufferedImage.getGraphics().drawImage(image, 0,0, srcW, srcH, null);

bufferedImage=new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY),null).filter(bufferedImage,null);

FileOutputStream fos = new FileOutputStream(img);

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fos);

encoder.encode(bufferedImage);

fos.close();

// System.out.println("轉換成功...");

} catch (IOException e) {

e.printStackTrace();

throw new IllegalStateException("圖片轉換出錯!", e);

}

}

}

java程序將彩色png圖片轉為黑白的

幫你搜了一段網上流行的代碼: 灰度變換 下面的程序使用三種方法對一個彩色圖像進行灰度變換,變換的效果都不一樣。一般而言,灰度變換的算法是將象素的三個顏色分量使用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

java怎么讀取圖片上所有點的像素,圖片是黑白,我想讀出黑白點然后再輸出#和空格,求代碼

throws?IOException

InputStream?in=new?InputStream(文件);

OutputStream?out=new?OutputStream();

StringBuilder?sb=new?StringBuilder();

while((ch=in.read)!=-1)

{

if(sb.length()!=8)

{

sb.append(ch);

}

else

{

String?str=sb.toString();

if(Integer.toHexString(Integer.parseInt(str)).equals("FFFFFF"))

System.out.println("#");

else?if(Integer.toHexString(Integer.parseInt(str)).equals("000000"))

System.out.println("?");

sb=sb.del(0,sb.length());

}

}

in.close();

out.close();

處理異常就不寫了,直接跑了,你應該會吧

本文標題:java圖片變成黑白代碼,java圖片變成黑白代碼了
URL標題:http://m.kartarina.com/article20/hegejo.html

成都網站建設公司_創新互聯,為您提供企業網站制作、手機網站建設品牌網站制作云服務器、關鍵詞優化、搜索引擎優化

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

成都定制網站網頁設計
主站蜘蛛池模板: 免费人成无码大片在线观看 | 久久久久亚洲AV无码网站| 天天看高清无码一区二区三区| 国产精品亚洲а∨无码播放不卡| 亚洲中文字幕无码久久2017| 性色av极品无码专区亚洲| 国产成人无码免费网站| 亚洲人成网亚洲欧洲无码| 亚洲人成网亚洲欧洲无码久久| 国产精品无码久久四虎| 久久亚洲AV成人无码电影| 日韩精品无码人成视频手机 | 无码人妻久久一区二区三区 | 精品无码一区二区三区爱欲| 亚洲国产成人精品无码久久久久久综合 | 潮喷失禁大喷水aⅴ无码| 精品久久久无码人妻中文字幕豆芽| 亚洲va无码手机在线电影| 无码 免费 国产在线观看91| 亚洲性无码AV中文字幕| 久久午夜伦鲁片免费无码| 亚洲人成人无码网www电影首页 | 国产成人年无码AV片在线观看| 久久亚洲日韩看片无码| 亚洲AV无码专区电影在线观看| 精品无码人妻久久久久久| 人妻少妇精品无码专区动漫| 亚洲av无码专区在线观看下载| 无码国产午夜福利片在线观看| 亚洲AV无码一区二区乱孑伦AS| 波多野42部无码喷潮在线| 亚洲一本大道无码av天堂| 国产精品无码素人福利免费| 无码人妻aⅴ一区二区三区| 亚洲av无码一区二区三区人妖| 精品无码一区二区三区电影 | 亚洲中文久久精品无码| 国产成人无码AV一区二区在线观看| 丝袜无码一区二区三区| 国产精品无码AV一区二区三区| 亚洲欧洲美洲无码精品VA|