⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bmpoperatorframe.java

📁 用java实现的对位图文件读取的源程序代码。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import javax.swing.*;
//import javax.swing.JTextArea;

import java.util.Map;
import java.util.HashMap;

public class BMPOperatorFrame extends Frame implements ActionListener {
	
	BMP bmp;
	boolean existBMP = false;
	
	BMPPanel2 bmpPl;
	Panel infoPl;
	Label infoLb;
	
	Button openBn 		= new Button("打开");
	Button saveBn 		= new Button("保存");
	Button resetBn 		= new Button("还原");
	
	Label redLb 		= new Label("红");
	Label greenLb 		= new Label("绿");
	Label blueLb 		= new Label("蓝");
	Label redErrorLb 	= new Label("误差");
	Label greenErrorLb 	= new Label("误差");
	Label blueErrorLb 	= new Label("误差");
	
	Choice redChc 		= new Choice();
	Choice greenChc 	= new Choice();
	Choice blueChc 		= new Choice();

	Choice redErrorChc 		= new Choice();
	Choice greenErrorChc 	= new Choice();
	Choice blueErrorChc 	= new Choice();
	
	Button pickupBn 	= new Button("提取");
	Button shieldBn 	= new Button("屏蔽");
	
	Button reverseBn 	= new Button("反色");
	Button acuteBn 		= new Button("锐化");
		
	
	String[] patternName = {"Sobel_x", "Sobel_y","Prewitt_x", "Prewitt_y"
							,"My_0","My_1", "My_2", "My_3", "My_4"};
	Choice patternChc = new Choice();
	
	final public static Map<String,Integer> PATTERN_MAP = new HashMap<String,Integer>();
	static {
		PATTERN_MAP.put("Sobel_x",BMPProcess.SOBEL_X);
		PATTERN_MAP.put("Sobel_y",BMPProcess.SOBEL_Y);
		
		PATTERN_MAP.put("Prewitt_x",BMPProcess.PREWITT_X);
		PATTERN_MAP.put("Prewitt_y",BMPProcess.PREWITT_Y);
		
	//	PATTERN_MAP.put(D_X,8);
	//	PATTERN_MAP.put(D_Y,0);
		
		PATTERN_MAP.put("My_0",BMPProcess.MY_0);
		PATTERN_MAP.put("My_1",BMPProcess.MY_1);
		PATTERN_MAP.put("My_2",BMPProcess.MY_2);
		PATTERN_MAP.put("My_3",BMPProcess.MY_3);
		PATTERN_MAP.put("My_4",BMPProcess.MY_4);
	}
	
	
	Button binaryByColorBn 		= new Button("二值图(颜色分割)");	
	Button binaryByMaxRateBn 	= new Button("二值图(比率分割)");
		
	Label histogramLb 				= new Label("直方图");
	Button histogramRedBn 			= new Button("红");
	Button histogramGreenBn 		= new Button("绿");
	Button histogramBlueBn 			= new Button("蓝");
	
	Label histogramMoveLb 			= new Label("直方图修护");
	Button histogramMoveRedBn 		= new Button("红");
	Button histogramMoveGreenBn 	= new Button("绿");
	Button histogramMoveBlueBn 		= new Button("蓝");
	Button histogramMoveBn 			= new Button("全部");
	
	Label showLb 			= new Label("颜色显示");
	Button showRedBn 		= new Button("红");
	Button showGreenBn 		= new Button("绿");
	Button showBlueBn 		= new Button("蓝");
	
	
	Label smoothLb 			= new Label("平滑");
	Button equalBn	 		= new Button("平均");
	Button middleBn 		= new Button("中值");
	
	//double zoomSize = 1;
	
    /**
     * The constructor.
     */  
     public BMPOperatorFrame() {
                
        init();
        
        // Add window listener.
        this.addWindowListener
        (
            new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    BMPOperatorFrame.this.windowClosed();
                }
            }
        );  
    }
    HistogramFrame aHistogramFrame;
    
	private void fillChoice00_FF(Choice choice,int step) {
    	fillChoice00_FF(choice,0,0XFF,step);
    }
    
    private void fillChoice00_FF(Choice choice,int start, int end,int step) {
    	for (int i=start; i<end; i+=step) {
    		choice.add(Integer.toHexString(i).toUpperCase());
    	}
    	choice.select(0);
    }
    
    private void fillChc(Choice choice,String[] items) {
    	for (int i = 0; i<items.length; i++) {
    		choice.add(items[i]);
	    }
    }
    
    public void init() {
    	
    	Panel toolPl = new Panel(new GridLayout(2,1,0,0));
    	
    	Panel toolPl1 = new Panel();
    	Panel toolPl2 = new Panel();
    	Panel toolPl3 = new Panel();
    	
    	bmpPl = new BMPPanel2();
    	infoPl = new Panel();
    	
    	addAllButtonAction();
    	setAllButtonUnable();

    	toolPl1.add(openBn);
    	//toolPl1.add(saveBn);
    	toolPl1.add(resetBn);   	
    	
    	toolPl1.add(reverseBn);
    	toolPl1.add(acuteBn);
    	fillChc(this.patternChc,this.patternName);
    	toolPl1.add(patternChc);
    	//toolPl1.add(binaryByColorBn);
    	//toolPl1.add(binaryByMaxRateBn);
    	//toolPl1.add(histogramBn);
    	
    	toolPl2.add(histogramLb);
    	toolPl2.add(histogramRedBn);
    	toolPl2.add(histogramGreenBn);
    	toolPl2.add(histogramBlueBn);
    	
    	toolPl2.add(new Label("    "));
    	
    	toolPl2.add(histogramMoveLb);
    	toolPl2.add(histogramMoveRedBn);
    	toolPl2.add(histogramMoveGreenBn);
    	toolPl2.add(histogramMoveBlueBn);
    	toolPl2.add(histogramMoveBn);
    	/*
    	toolPl2.add(new Label("    "));
    	
    	toolPl2.add(showLb);
    	toolPl2.add(showRedBn);
    	toolPl2.add(showGreenBn);
    	toolPl2.add(showBlueBn);
    	
    	fillChoice00_FF(redChc,16);
    	fillChoice00_FF(greenChc,16);
    	fillChoice00_FF(blueChc,16);

		fillChoice00_FF(redErrorChc,0,0Xff,4);
    	fillChoice00_FF(greenErrorChc,0,0Xff,4);
    	fillChoice00_FF(blueErrorChc,0,0Xff,4);
    	
    	
    	toolPl3.add(redLb);
    	toolPl3.add(redChc);
    	toolPl3.add(redErrorLb);
    	toolPl3.add(redErrorChc);
    	
    	toolPl3.add(greenLb);
    	toolPl3.add(greenChc);
    	toolPl3.add(greenErrorLb);
    	toolPl3.add(greenErrorChc);
    	
    	toolPl3.add(blueLb);
    	toolPl3.add(blueChc);
    	toolPl3.add(blueErrorLb);
    	toolPl3.add(blueErrorChc);
    	toolPl2.add(new Label("    "));
    	
    	toolPl3.add(pickupBn);
    	toolPl3.add(shieldBn);
    	
    	*/
    	toolPl1.add(new Label("  "));
    	toolPl1.add(smoothLb);
    	toolPl1.add(equalBn);
    	toolPl1.add(middleBn);
    	
    	toolPl.add(toolPl1);
    	toolPl.add(toolPl2);
    	//toolPl.add(toolPl3);
    	
    	String initStr = "                          ";
    	infoLb = new Label(initStr);
    	infoPl.add(infoLb);
    	
    	
    	add(toolPl,BorderLayout.NORTH);
    	add(bmpPl,BorderLayout.CENTER);
    	add(infoPl,BorderLayout.SOUTH);
    	
    	aHistogramFrame = new HistogramFrame();
    }
    
    public void addAllButtonAction() {
    	openBn.addActionListener(this);
    	resetBn.addActionListener(this);
    	saveBn.addActionListener(this);
    	
    	//roomInBn.addActionListener(this);    	
    	pickupBn.addActionListener(this);
    	shieldBn.addActionListener(this);
    	reverseBn.addActionListener(this);
    	acuteBn.addActionListener(this);
    	
    	
    	binaryByColorBn.addActionListener(this);
    	binaryByMaxRateBn.addActionListener(this);
    	
    	histogramRedBn.addActionListener(this);
    	histogramGreenBn.addActionListener(this);
    	histogramBlueBn.addActionListener(this);
    	
    	histogramMoveRedBn.addActionListener(this);
    	histogramMoveGreenBn.addActionListener(this);
    	histogramMoveBlueBn.addActionListener(this);
    	histogramMoveBn.addActionListener(this);
    	
    	showRedBn.addActionListener(this);
    	showGreenBn.addActionListener(this);
    	showBlueBn.addActionListener(this);
    	
    	equalBn.addActionListener(this);
    	middleBn.addActionListener(this);
    }
    
    public void setButtonEnable(Button bn) {
    	bn.setEnabled(true);
    }
    
    public void setAllButtonEnable() {
    	
    	//setButtonEnable(saveBn);
    	setButtonEnable(resetBn);
    	
    	//setButtonEnable(roomInBn);
    	setButtonEnable(pickupBn);
    	setButtonEnable(shieldBn);
    	setButtonEnable(reverseBn);
    	setButtonEnable(acuteBn);
    	
    	setButtonEnable(binaryByColorBn);
    	
    	setButtonEnable(histogramRedBn);
    	setButtonEnable(histogramGreenBn);
    	setButtonEnable(histogramBlueBn);
    	
    	setButtonEnable(histogramMoveRedBn);
    	setButtonEnable(histogramMoveGreenBn);
    	setButtonEnable(histogramMoveBlueBn);
    	setButtonEnable(histogramMoveBn);
    	
    	setButtonEnable(showRedBn);
    	setButtonEnable(showGreenBn);
    	setButtonEnable(showBlueBn);
    	
    	setButtonEnable(equalBn);
    	setButtonEnable(middleBn);
    	
    	if (bmp.type == 8) {
    		setButtonEnable(binaryByMaxRateBn);     		
    	}
    }
    
    public void setAllButtonUnable() {
    	
    	setButtonUnable(saveBn);
    	setButtonUnable(resetBn);
    	
    	setButtonUnable(pickupBn);
    	setButtonUnable(shieldBn);
    	setButtonUnable(reverseBn);
    	setButtonUnable(acuteBn);
    	
    	setButtonUnable(binaryByColorBn);
    	setButtonUnable(binaryByMaxRateBn);
    	
    	setButtonUnable(histogramRedBn);
    	setButtonUnable(histogramGreenBn);
    	setButtonUnable(histogramBlueBn);
    	
    	setButtonUnable(histogramMoveRedBn);
    	setButtonUnable(histogramMoveGreenBn);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -