-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPixelOperationsPic.java
More file actions
57 lines (51 loc) · 1.54 KB
/
PixelOperationsPic.java
File metadata and controls
57 lines (51 loc) · 1.54 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// Torbert, 24 July 2013
//
import java.awt.Color;
import java.awt.image.BufferedImage;
//
public class PixelOperationsPic
{
public Color[][] getArray(BufferedImage img) //defalt, regular image
{
Color[][] arr;
int numcols = img.getWidth();
int numrows = img.getHeight();
arr = new Color[numrows][numcols];
for(int j = 0; j < arr.length; j++)
{
for(int k = 0; k < arr[0].length; k++)
{
int rgb = img.getRGB(k,j);
arr[j][k] = new Color(rgb);
}
}
//
return arr;
}
public void setImage(BufferedImage img, Color[][] arr) //resetting to original
{
for(int j = 0; j < arr.length; j++)
{
for(int k = 0; k < arr[0].length; k++)
{
Color tmp = arr[j][k];
//
int rgb = tmp.getRGB();
//
img.setRGB(k,j,rgb);
}
}
}
/**********************************************************************/
public void hidePixels(Color[][] arr, int horiStart, int horiStop, int vertiStart, int vertiStop) //hides at certain location, transferring from a user-assumed 400 by 400 grid
{
for(int j = (int)((arr.length*horiStart)/400); j < (int)((arr.length*horiStop)/400); j++)
{
for(int k = (int)((arr[0].length*vertiStart)/400); k < (int)((arr[0].length*vertiStop)/400); k++)
{
arr[j][k] = Color.BLACK;
}
}
}
}