1 package sample2;
2
3 import fi.jyu.mit.graphics.EasyWindow;
4 import fi.jyu.mit.graphics.Bitmap;
5 import static fi.jyu.mit.graphics.Bitmap.*;
6
7
12 public class BitmapSample {
13
14
18 public static void convertGrayScale(Bitmap bm) {
19 for (int y = 0; y < bm.getHeight(); y++) {
20 for (int x = 0; x < bm.getWidth(); x++) {
21 int c = bm.getRGB(x, y);
22 int b = brightness(c);
23 int c2 = packRGB(b, b, b);
24 bm.setRGB(x, y, c2);
25 }
26 }
27 }
28
29
38 public static void main(String[] args) {
39 Bitmap bm1 = new Bitmap(0,0,"sample/CarSample.png");
40 Bitmap bm2 = new Bitmap(bm1.getWidth(),0, bm1);
41 Bitmap bm3 = new Bitmap(0, bm1.getHeight(), bm1);
42 Bitmap bm4 = new Bitmap(bm1.getWidth(), bm1.getHeight(), bm1);
43 EasyWindow window = new EasyWindow(bm1.getWidth()*2,bm1.getHeight()*2);
44 window.add(bm1);
45 window.add(bm2);
46 window.add(bm3);
47 window.add(bm4);
48
49 convertGrayScale(bm2);
50 bm3.andPixels(packRGB(255,0,0));
51 bm4.orPixels(packRGB(255,0,0));
52
53 window.redraw();
54 }
55
56 }
57