-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPNGCanvas.java
More file actions
39 lines (31 loc) · 958 Bytes
/
PNGCanvas.java
File metadata and controls
39 lines (31 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.awt.Color;
import javax.imageio.ImageIO;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.io.File;
import java.awt.Point;
import java.util.*;
public class PNGCanvas {
public int width, height;
public Color[][] pixels;
public PNGCanvas(int width, int height){
this.width = width;
this.height = height;
pixels = new Color[width][height];
}
public int intensity(int x, int y) {
return (int)((GetPixel(x,y).getRed()/3)+(GetPixel(x,y).getBlue()/3)+(GetPixel(x,y).getGreen()/3));
}
public Color GetPixel(Point z){
if((z.x<0) || z.x>=width || z.y<0 || z.y>=height) return null;
return pixels[z.x][z.y];
}
public Color GetPixel(int x, int y){
if((x<0) || x>=width || y<0 || y>=height) return null;
return pixels[x][y];
}
public void SetPixel(int x, int y, Color colour){
if((x<0) || x>=width || y<0 || y>=height) return;
pixels[x][y] = colour;
}
}