java 디지털 이미지 처리 기반 이미지 파일 쓰기 예시 사용하기
File file = new File("D:\\test\\blue_flower.jpg");
BufferedImage image = ImageIO.read(file);
File outputfile = new File("saved.png");
ImageIO.write(bufferedImage, "png",outputfile);
int type= image.getType();
if ( type ==BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB )
return (int [])image.getRaster().getDataElements(x, y, width, height, pixels );
else
return image.getRGB( x, y, width, height, pixels, 0, width );
int type= image.getType();
if ( type ==BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB )
image.getRaster().setDataElements(x, y, width, height, pixels );
else
image.setRGB(x, y, width, height, pixels, 0, width );
 package com.gloomyfish.swing;
 import java.awt.BorderLayout;
 import java.awt.Dimension;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.RenderingHints;
 import java.awt.image.BufferedImage;
 import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.JFrame;
public class PlasmaDemo extends JComponent {  
    /** 
     *  
     */  
    private static final long serialVersionUID = -2236160343614397287L;  
    private BufferedImage image = null;  
    private int size = 256;
    public PlasmaDemo() {  
        super();  
        this.setOpaque(false);  
    }  
    protected void paintComponent(Graphics g) {  
        Graphics2D g2 = (Graphics2D)g;  
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);  
        g2.drawImage(getImage(), 5, 5, image.getWidth(), image.getHeight(), null);  
    }  
    private BufferedImage getImage() {  
        if(image == null) {  
            image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);  
            int[] rgbData = new int[size*size];  
            generateNoiseImage(rgbData);  
            setRGB(image, 0, 0, size, size, rgbData);
            File outFile = new File("plasma.jpg");
            try {
                ImageIO.write(image, "jpg", outFile);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }  
        return image;  
    }  
    public void generateNoiseImage(int[] rgbData) {  
        int index = 0;  
        int a = 255;  
        int r = 0;  
        int g = 0;  
        int b = 0;  
        for(int row=0; row<size; row++) {  
            for(int col=0; col<size; col++) {  
                // set random color value for each pixel  
                r = (int)(128.0 + (128.0 * Math.sin((row + col) / 8.0)));  
                g = (int)(128.0 + (128.0 * Math.sin((row + col) / 8.0)));  
                b = (int)(128.0 + (128.0 * Math.sin((row + col) / 8.0)));  
                rgbData[index] = ((clamp(a) & 0xff) << 24) |  
                                ((clamp(r) & 0xff) << 16)  |  
                                ((clamp(g) & 0xff) << 8)   |  
                                ((clamp(b) & 0xff));  
                index++;  
            }  
        }  
    }  
    private int clamp(int rgb) {  
        if(rgb > 255)  
            return 255;  
        if(rgb < 0)  
            return 0;  
        return rgb;  
    }    
    public void setRGB( BufferedImage image, int x, int y, int width, int height, int[] pixels ) {  
        int type = image.getType();  
        if ( type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB )  
            image.getRaster().setDataElements( x, y, width, height, pixels );  
        else  
            image.setRGB( x, y, width, height, pixels, 0, width );  
    }  
    public static void main(String[] args) {  
        JFrame frame = new JFrame("Noise Art Panel");  
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
        frame.getContentPane().setLayout(new BorderLayout());  
        frame.getContentPane().add(new PlasmaDemo(), BorderLayout.CENTER);  
        frame.setPreferredSize(new Dimension(400 + 25,450));  
       frame.pack();  
       frame.setVisible(true);  
   }  
}  
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
opencv 기하학적 형상 추출기하학적 형상 식별(삼각형, 사각형/사각형, 다각형, 원 식별) 기하학적 형상 면적과 둘레, 중심 위치 계산 구체적인 코드 실현과 프로그램 시범을 보이기 전에 우리는 먼저 몇 가지 개념을 분명히 해야 한다. 1. 기...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.