1 | static BufferedImage blendBufferedImages(BufferedImage bi1, BufferedImage bi2) {
|
2 | ret blendBufferedImages(bi1, bi2, 0.5);
|
3 | }
|
4 |
|
5 | static BufferedImage blendBufferedImages(BufferedImage bi1, BufferedImage bi2, double weight2) {
|
6 | double weight = 1-weight2;
|
7 |
|
8 | int width = bi1.getWidth ();
|
9 | if (width != bi2.getWidth ())
|
10 | fail("widths not equal");
|
11 |
|
12 | int height = bi1.getHeight ();
|
13 | if (height != bi2.getHeight ())
|
14 | fail("heights not equal");
|
15 |
|
16 | BufferedImage bi3 = new BufferedImage (width, height,
|
17 | BufferedImage.TYPE_INT_RGB);
|
18 | int [] rgbim1 = new int [width];
|
19 | int [] rgbim2 = new int [width];
|
20 | int [] rgbim3 = new int [width];
|
21 |
|
22 | for (int row = 0; row < height; row++)
|
23 | {
|
24 | bi1.getRGB (0, row, width, 1, rgbim1, 0, width);
|
25 | bi2.getRGB (0, row, width, 1, rgbim2, 0, width);
|
26 |
|
27 | for (int col = 0; col < width; col++)
|
28 | {
|
29 | int rgb1 = rgbim1 [col];
|
30 | int r1 = (rgb1 >> 16) & 255;
|
31 | int g1 = (rgb1 >> 8) & 255;
|
32 | int b1 = rgb1 & 255;
|
33 |
|
34 | int rgb2 = rgbim2 [col];
|
35 | int r2 = (rgb2 >> 16) & 255;
|
36 | int g2 = (rgb2 >> 8) & 255;
|
37 | int b2 = rgb2 & 255;
|
38 |
|
39 | int r3 = (int) (r1*weight+r2*(1.0-weight));
|
40 | int g3 = (int) (g1*weight+g2*(1.0-weight));
|
41 | int b3 = (int) (b1*weight+b2*(1.0-weight));
|
42 | rgbim3 [col] = (r3 << 16) | (g3 << 8) | b3;
|
43 | }
|
44 |
|
45 | bi3.setRGB (0, row, width, 1, rgbim3, 0, width);
|
46 | }
|
47 |
|
48 | return bi3;
|
49 | } |