-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitmap.java
More file actions
44 lines (38 loc) · 1.1 KB
/
Bitmap.java
File metadata and controls
44 lines (38 loc) · 1.1 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
/**
* Bitmap
*/
import java.awt.*;
import java.util.Arrays;
public class Bitmap {
private final int m_width;
private final int m_height;
private final byte m_components[];//bitmap array
public Bitmap(int width, int height){
m_width = width;
m_height = height;
m_components = new byte[m_width*m_height*4];//creates a byte array with alpha,b,g,r bitmap
}
public void clear(byte shade){
Arrays.fill(m_components, shade);
}
public void drawPixel(int x, int y,byte a,byte b,byte g,byte r){
/*
assigns the bitmap value to the particular pixels
*/
int index = (x + y*m_width)*4;
m_components[index] = a;
m_components[index+1]= b;
m_components[index+2]= g;
m_components[index+3]= r;
}
public void copyToByteArray(byte dest[]){
for(int i=0; i < m_height*m_width ; i++){
//sets dest byte array to the m_comp bitmap value
dest[i*3]= m_components[i*4+1];
dest[(i*3)+1]= m_components[i*4+2];
dest[(i*3)+2]= m_components[i*4+3];
}
}
public int Get_width(){return m_width;}
public int Get_height(){return m_height;}
}