织云等待中...

12.14总结

生病ing

package Vfx;

import okhttp3.*;
import org.json.JSONObject;

import javax.imageio.ImageIO;
import javax.swing.;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.
;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;

public class Enhance {

public static final String API_KEY = "azh8NUHqQ6xfYxsycMj5064k";
public static final String SECRET_KEY = "RCrBgDCGT0gA0H0XuHHf8POXX5ExAi4G";

static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();
static String accessToken;

public static void main(String[] args) {
    JFrame frame = new JFrame("Image Processing");
    frame.setSize(800, 500);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLabel imageLabel = new JLabel();
    imageLabel.setBounds(0, 100, 300, 300);

    JLabel enhancedImageLabel = new JLabel();
    enhancedImageLabel.setBounds(350, 100, 300, 300);

    JButton addButton = new JButton("添加图片");
    JButton enhanceButton = new JButton("图像清晰度增强");

    addButton.setBounds(50, 50, 150, 30);
    enhanceButton.setBounds(400, 50, 150, 30);

    addButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileChooser = new JFileChooser();
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Image Files", "jpg", "jpeg", "png", "gif");
            fileChooser.setFileFilter(filter);

            int result = fileChooser.showOpenDialog(null);
            if (result == JFileChooser.APPROVE_OPTION) {
                File selectedFile = fileChooser.getSelectedFile();
                String imagePath = selectedFile.getAbsolutePath();

                // 显示选择的图片并缩放大小
                ImageIcon imageIcon = new ImageIcon(imagePath);
                Image originalImage = imageIcon.getImage();
                int originalWidth = originalImage.getWidth(null);
                int originalHeight = originalImage.getHeight(null);

                int newWidth = 300;
                int newHeight = (int) (originalHeight * ((double) newWidth / originalWidth));

                Image scaledImage = originalImage.getScaledInstance(newWidth, newHeight, Image.SCALE_DEFAULT);
                ImageIcon scaledImageIcon = new ImageIcon(scaledImage);
                imageLabel.setIcon(scaledImageIcon);
            }
        }
    });
posted @ 2023-12-14 15:43  奉禾  阅读(12)  评论(0)    收藏  举报