Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- import javax.imageio.ImageIO;
- public class Kep extends Component {
- public static void main(String[] foo) {
- new Kep();
- }
- private void marchThroughImage(BufferedImage image) throws IOException {
- int w = image.getWidth();
- int h = image.getHeight();
- BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
- System.out.println("width, height: " + w + ", " + h);
- for (int i = 0; i < h; i++) {
- for (int j = 0; j < w; j++) {
- Color mycolor = new Color(image.getRGB(i, j));
- int red = mycolor.getRed();
- int green = mycolor.getGreen();
- int blue = mycolor.getBlue();
- int alpha = mycolor.getAlpha();
- int col = (alpha << 24) | (red << 16) | (green << 8) | blue;
- img.setRGB(i, j, col);
- }
- }
- File f = new File("MyFile.png");
- ImageIO.write(img, "PNG", f);
- }
- public Kep() {
- try {
- BufferedImage image =
- ImageIO.read(this.getClass().getResource("asd.png"));
- marchThroughImage(image);
- } catch (IOException e) {
- System.err.println(e.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement