📄 bmpoperatorframe.java
字号:
setButtonUnable(histogramMoveBlueBn);
setButtonUnable(histogramMoveBn);
setButtonUnable(showRedBn);
setButtonUnable(showGreenBn);
setButtonUnable(showBlueBn);
setButtonUnable(equalBn);
setButtonUnable(middleBn);
}
protected void setButtonUnable(Button bn) {
bn.setEnabled(false);
}
public int getPickupColor() {
int red = Integer.parseInt(redChc.getSelectedItem(),16);
int green = Integer.parseInt(greenChc.getSelectedItem(),16);
int blue = Integer.parseInt(blueChc.getSelectedItem(),16);
return (red<<16) + (green<<8) + blue;
}
public int getErrorValue() {
int red = Integer.parseInt(redErrorChc.getSelectedItem(),16);
int green = Integer.parseInt(greenErrorChc.getSelectedItem(),16);
int blue = Integer.parseInt(blueErrorChc.getSelectedItem(),16);
return (red<<16) + (green<<8) + blue;
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == openBn) {
doWhenOpen();
} else if(e.getSource() == saveBn) {
} else if(e.getSource() == resetBn) {
doWhenReset();
} else if(e.getSource() == pickupBn) {
doWhenPickupBn();
} else if(e.getSource() == shieldBn) {
doWhenShieldBn();
} else if(e.getSource() == reverseBn) {
doWhenReverse();
} else if(e.getSource() == acuteBn) {
doWhenAcute();
}
else if(e.getSource() == binaryByColorBn) {
doWhenDrawBinaryByColor();
} else if(e.getSource() == binaryByMaxRateBn) {
doWhenDrawBinaryByMaxRate();
}
else if(e.getSource() == histogramRedBn) {
doWhenShowHistogramRed();
} else if(e.getSource() == histogramGreenBn) {
doWhenShowHistogramGreen();
} else if(e.getSource() == histogramBlueBn) {
doWhenShowHistogramBlue();
}
else if(e.getSource() == histogramMoveRedBn) {
doWhenHistogramMoveRed();
} else if(e.getSource() == histogramMoveGreenBn) {
doWhenHistogramMoveGreenBn();
} else if(e.getSource() == histogramMoveBlueBn) {
doWhenHistogramMoveBlueBn();
} else if(e.getSource() == histogramMoveBn) {
doWhenHistogramMoveBn();
}
else if(e.getSource() == showRedBn) {
doWhenShowRed();
} else if(e.getSource() == showGreenBn) {
doWhenShowGreen();
} else if(e.getSource() == showBlueBn) {
doWhenShowBlue();
}
else if(e.getSource() == equalBn) {
doWhenSmoothByEqual();
} else if(e.getSource() == middleBn) {
doWhenSmoothByMiddle();
}
}
boolean isBMP = true;
public void doWhenOpen() {
setAllButtonUnable();
//color = null;
String title = "选择位图文件(bmp或BMP)";
FileDialog openDialog = new FileDialog(this,title,FileDialog.LOAD);
String filePath = "";
String fileName = "";
openDialog.setVisible(true);
fileName = openDialog.getFile();
/*
while (fileName != null && !fileName.matches(".*\\.((bmp)|(BMP))")){
JOptionPane.showMessageDialog(this,"选择位图(bmp|BMP)文件");
openDialog.setVisible(true);
fileName = openDialog.getFile();
}*/
if (fileName == null) {
return ;
}
if (fileName.matches(".*\\.((bmp)|(BMP))")) {
filePath = openDialog.getDirectory().replace("\\","\\\\");
try {
bmp = new BMP(filePath + fileName);
} catch(Exception e) {
JOptionPane.showMessageDialog(this,e.getMessage());
e.printStackTrace();
return;
}
isBMP = true;
} else if (fileName.matches(".*\\.((jpg)|(JPG)|(png)|(PNG)|(gif)|(GIF))")) {
filePath = openDialog.getDirectory().replace("\\","\\\\");
try {
ImageX imageX = new ImageX(filePath + fileName,bmpPl);
bmp = new BMP();
bmp.setOriginData(imageX.getData());
} catch(Exception e) {
JOptionPane.showMessageDialog(this,e.getMessage());
e.printStackTrace();
return;
}
isBMP = false;
} else {
return;
}
doWhenLoadOver();
}
public void doWhenLoadOver() {
setAllButtonEnable();
if (isBMP) {
String space = ", ";
String imageInfo = bmp.getProperty();
infoLb.setText(imageInfo.replaceAll("\n",space));
}
bmpPl.drawBMP(bmp.getData());
}
public void doWhenReset() {
bmpPl.drawBMP(bmp.getOriginData());
}
public void doWhenPickupBn() {
int pickupColor = this.getPickupColor();
int error = this.getErrorValue();
int[][] data = bmp.getPickupData(pickupColor,error);
int x0 = bmpPl.getBMPX0();
int y0 = bmpPl.getBMPY0();
int width = bmpPl.getBMPWidth();
int height = bmpPl.getBMPHeight();
bmpPl.drawBMP(data,x0,y0,width,height);
}
public void doWhenShieldBn() {
int pickupColor = this.getPickupColor();
int error = this.getErrorValue();
int[][] data = bmp.getShieldData(pickupColor,error);
int x0 = bmpPl.getBMPX0();
int y0 = bmpPl.getBMPY0();
int width = bmpPl.getBMPWidth();
int height = bmpPl.getBMPHeight();
bmpPl.drawBMP(data,x0,y0,width,height);
}
public void doWhenReverse() {
bmpPl.drawBMPBaseBefore(bmp.getReverseData());
}
public void doWhenAcute() {
String patternStr = patternChc.getSelectedItem();
final int TYPE = PATTERN_MAP.get(patternStr);
bmpPl.drawBMPBaseBefore(bmp.getAcuteData(TYPE));
}
public void doWhenDrawBinaryByColor() {
//bmpPl.drawBinaryBMPByColor();
}
public void doWhenDrawBinaryByMaxRate() {
if (bmp.type != 8) {
return;
}
//Color maxRateColor = bmp.getMaxRateColor();
// bmpPl.drawBinaryBMPByMax(maxRateColor);
}
public void doWhenShowHistogramRed() {
showHistogram(BMPProcess.RED);
}
public void doWhenShowHistogramGreen() {
showHistogram(BMPProcess.GREEN);
}
public void doWhenShowHistogramBlue() {
showHistogram(BMPProcess.BLUE);
}
final static Map<Integer,String> nameMap = new HashMap<Integer,String>(2);
{
nameMap.put(BMPProcess.RED,"红色分量的直方图");
nameMap.put(BMPProcess.GREEN,"绿色分量的直方图");
nameMap.put(BMPProcess.BLUE,"蓝色分量的直方图");
}
public void showHistogram(final int TYPE) {
final long imageSize = bmp.getImageSize(isBMP);
int[][] data = bmp.getData();
int[] histogram = BMPProcess.getHistogram(data,TYPE);
float[] percent = BMPProcess.getPercent(histogram,imageSize);
double entropy = BMPProcess.getEntropy(percent);
//Toolbox.println(percent);
aHistogramFrame = new HistogramFrame();
aHistogramFrame.setPercent(percent);
aHistogramFrame.setEntropy(entropy);
aHistogramFrame.setTitle(nameMap.get(TYPE));
aHistogramFrame.setVisible(true);
}
public void doWhenHistogramMoveRed() {
bmpPl.drawBMPBaseBefore(bmp.getNewRedData());
}
public void doWhenHistogramMoveGreenBn() {
bmpPl.drawBMPBaseBefore(bmp.getNewGreenData());
}
public void doWhenHistogramMoveBlueBn() {
bmpPl.drawBMPBaseBefore(bmp.getNewBlueData());
}
public void doWhenHistogramMoveBn() {
bmpPl.drawBMPBaseBefore(bmp.getNewData());
}
public void doWhenShowRed() {
bmpPl.drawBMPBaseBefore(bmp.getRedData());
}
public void doWhenShowGreen() {
bmpPl.drawBMPBaseBefore(bmp.getGreenData());
}
public void doWhenShowBlue() {
bmpPl.drawBMPBaseBefore(bmp.getBlueData());
}
public void doWhenSmoothByEqual() {
bmpPl.drawBMPBaseBefore(bmp.getSmoothByEqual());
}
public void doWhenSmoothByMiddle() {
bmpPl.drawBMPBaseBefore(bmp.getSmoothByMiddle());
}
/**
* Shutdown procedure when run as an application.
*/
protected void windowClosed() {
System.exit(0);
}
public int[][] getPattern() {
String title = "input the pattern";
JTextArea text = new JTextArea(5,15);
JPanel panel = new JPanel();
panel.add(text);
String patternStr = JOptionPane.showInputDialog(panel,title);
String[] rowData = patternStr.split("\n");
int[][] pattern = new int[rowData.length][];
String[] colData = null;
for (int i = 0; i<rowData.length; i++) {
colData = rowData[i].split("\t| {1,7}|,");
pattern[i] = new int[colData.length];
for (int j = 0; j<colData.length; j++) {
pattern[i][j] = Integer.parseInt(colData[j]);
}
}
return pattern;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -