Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

49
LINES

< > BotCompany Repo | #1015024 // blendBufferedImages

JavaX fragment (include)

static BufferedImage blendBufferedImages(BufferedImage bi1, BufferedImage bi2) {
  ret blendBufferedImages(bi1, bi2, 0.5);
}

static BufferedImage blendBufferedImages(BufferedImage bi1, BufferedImage bi2, double weight2) {
 double weight = 1-weight2;
 
 int width = bi1.getWidth ();
 if (width != bi2.getWidth ())
   fail("widths not equal");

 int height = bi1.getHeight ();
 if (height != bi2.getHeight ())
   fail("heights not equal");

 BufferedImage bi3 = new BufferedImage (width, height,
                     BufferedImage.TYPE_INT_RGB);
 int [] rgbim1 = new int [width];
 int [] rgbim2 = new int [width];
 int [] rgbim3 = new int [width];

 for (int row = 0; row < height; row++)
 {
    bi1.getRGB (0, row, width, 1, rgbim1, 0, width);
    bi2.getRGB (0, row, width, 1, rgbim2, 0, width);

    for (int col = 0; col < width; col++)
    {
      int rgb1 = rgbim1 [col];
      int r1 = (rgb1 >> 16) & 255;
      int g1 = (rgb1 >> 8) & 255;
      int b1 = rgb1 & 255;

      int rgb2 = rgbim2 [col];
      int r2 = (rgb2 >> 16) & 255;
      int g2 = (rgb2 >> 8) & 255;
      int b2 = rgb2 & 255;

      int r3 = (int) (r1*weight+r2*(1.0-weight));
      int g3 = (int) (g1*weight+g2*(1.0-weight));
      int b3 = (int) (b1*weight+b2*(1.0-weight));
      rgbim3 [col] = (r3 << 16) | (g3 << 8) | b3;
    }

    bi3.setRGB (0, row, width, 1, rgbim3, 0, width);
 }

 return bi3;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

Comments [hide]

ID Author/Program Comment Date
1374 stefan From http://www.informit.com/articles/article.aspx?p=1245201 2018-05-07 01:37:54

add comment

Snippet ID: #1015024
Snippet name: blendBufferedImages
Eternal ID of this version: #1015024/2
Text MD5: e557eba863026cd3f3711671826d57f7
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-07 01:38:15
Source code size: 1428 bytes / 49 lines
Pitched / IR pitched: No / No
Views / Downloads: 686 / 734
Version history: 1 change(s)
Referenced in: [show references]