Converts an image in BINARY mode to RGB mode

@param img image
@return new MarvinImage instance in RGB mode
174912
public static MarvinImage binaryToRgb(MarvinImage img) {
        MarvinImage resultImage = new MarvinImage(img.getWidth(), img.getHeight(), MarvinImage.COLOR_MODEL_RGB);

        for (int y = 0; y < img.getHeight(); y++) {
            for (int x = 0; x < img.getWidth(); x++) {
                if (img.getBinaryColor(x, y)) {
                    resultImage.setIntColor(x, y, 0, 0, 0);
                } else {
                    resultImage.setIntColor(x, y, 255, 255, 255);
                }
            }
        }
        return resultImage;
    }
262593
public BufferedImage createImage() {

		BufferedImage image = null;
		Graphics2D graphics = null;

		for (int layer = 0; layer < 4; layer++) {

			BufferedImage layerImage = layeredImage[layer];

			if (layerImage != null) {

				if (image == null) {
					image = layerImage;
					graphics = layeredGraphics[layer];
				} else {
					graphics.drawImage(layerImage, 0, 0, null);
					layeredGraphics[layer].dispose();
					layerImage.flush();
				}

				layeredImage[layer] = null;
				layeredGraphics[layer] = null;
			}
		}

		if (graphics != null) {
			graphics.dispose();
		}

		return image;
	}
310153
public DrawerItem setRoundedImage(BitmapDrawable image, int imageMode) {
        return setImage(new RoundedAvatarDrawable(image.getBitmap()), imageMode);
    }
628510
private BufferedImage generateBlankImg() {
        BufferedImage image = new BufferedImage(w, h,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = (Graphics2D) image.getGraphics();
        //设置图片背景是白色
        g2.setColor(Color.WHITE);
        g2.fillRect(0, 0, w, h);
        g2.dispose();
        return image;
    }
1316639
public static BufferedImage createImg(String data, int width, int height) throws IOException {
        logger.debug("生成二维码，要生成的图片的宽为{}，高为{}", width, height);
        QRCode code = createQRCode(data, width, height);
        BufferedImage image = ImageIO.read(new ByteArrayInputStream(code.stream().toByteArray()));
        logger.debug("二维码生成成功");
        return image;
    }
330882
public void setImage(BufferedImage img) {
        this.img = img;
        Dimension dim;
        if (img != null) {
            dim = new Dimension(img.getWidth(), img.getHeight());
        } else {
            dim = new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT);
        }

        setSize(dim);
        setPreferredSize(dim);
        repaint();
    }
283786
public static BufferedImage toBufferedImage(BitMatrix matrix, MatrixToImageConfig config) {
    int width = matrix.getWidth();
    int height = matrix.getHeight();
    BufferedImage image = new BufferedImage(width, height, config.getBufferedImageColorModel());
    int onColor = config.getPixelOnColor();
    int offColor = config.getPixelOffColor();
    int[] rowPixels = new int[width];
    BitArray row = new BitArray(width);
    for (int y = 0; y < height; y++) {
      row = matrix.getRow(y, row);
      for (int x = 0; x < width; x++) {
        rowPixels[x] = row.get(x) ? onColor : offColor;
      }
      image.setRGB(0, y, width, 1, rowPixels, 0, width);
    }
    return image;
  }
549794
public static BufferedImage renderBinary(GrayU8 binaryImage, boolean invert, BufferedImage out) {

		if( out == null || ( out.getWidth() != binaryImage.width || out.getHeight() != binaryImage.height) ) {
			out = new BufferedImage(binaryImage.getWidth(),binaryImage.getHeight(),BufferedImage.TYPE_BYTE_GRAY);
		}

		try {
			WritableRaster raster = out.getRaster();
			DataBuffer buffer = raster.getDataBuffer();
			if( buffer.getDataType() == DataBuffer.TYPE_BYTE ) {
				renderBinary(binaryImage, invert, (DataBufferByte)buffer, raster);
			} else if( buffer.getDataType() == DataBuffer.TYPE_INT ) {
				renderBinary(binaryImage, invert, (DataBufferInt)buffer, raster);
			} else {
				_renderBinary(binaryImage, invert,  out);
			}
		} catch( SecurityException e ) {
			_renderBinary(binaryImage, invert, out);
		}
		// hack so that it knows the buffer has been modified
		out.setRGB(0,0,out.getRGB(0,0));
		return out;
	}
277681
public static int registerImage(RenderedImage img) {
    synchronized(images) {
      int key = counter;
      counter++;
      assert (images.get(key) == null);
      images.put(key, new SoftReference<>(img));
      // Reorganize map, purge old entries
      if(counter % 50 == 49) {
        for(Iterator<SoftReference<RenderedImage>> iter = images.values().iterator(); iter.hasNext();) {
          SoftReference<RenderedImage> ref = iter.next();
          if(ref == null || ref.get() == null) {
            iter.remove();
          }
        }
      }
      if(LOG.isDebuggingFiner()) {
        LOG.debugFiner("Registered image: " + key);
      }
      return key;
    }
  }
124320
public JSONObject imageCensorComb(byte[] imgData, List<String> scenes, HashMap<String, String> options) {
        AipRequest request = new AipRequest();

        String base64Content = Base64Util.encode(imgData);
        request.addBody("image", base64Content);

        return imageCensorCombHelper(request, scenes, options);
    }
762327
public JSONObject imageCensorComb(String imgPath, EImgType type,
                                      List<String> scenes, HashMap<String, String> options) {
        if (type == EImgType.FILE) {
            try {
                byte[] imgData = Util.readFileByBytes(imgPath);
                return imageCensorComb(imgData, scenes, options);
            } catch (IOException e) {
                return AipError.IMAGE_READ_ERROR.toJsonResult();
            }
        }

        // url
        AipRequest request = new AipRequest();

        request.addBody("imgUrl", imgPath);

        return imageCensorCombHelper(request, scenes, options);
    }
48428
static BufferedImage convertImage (BufferedImage image) {
    switch (image.getType()) {
    case BufferedImage.TYPE_INT_ARGB_PRE:
      return image; // Already good to go
    case BufferedImage.TYPE_4BYTE_ABGR:
      image.coerceData(true); // Just premultiply the alpha and it's fine
      return image;
    }

    // Didn't know an easy thing to do, so create a whole new image in our preferred format
    BufferedImage convertedImage = new BufferedImage(image.getWidth(), image.getHeight(),
                                                     BufferedImage.TYPE_INT_ARGB_PRE);
    Graphics2D g = convertedImage.createGraphics();
    g.setColor(new java.awt.Color(0f, 0f, 0f, 0f));
    g.fillRect(0, 0, image.getWidth(), image.getHeight());
    g.drawImage(image, 0, 0, null);
    g.dispose();

    return convertedImage;
  }
594702
def set_image(self, img):
        ''''''
        self._bmp = wx.BitmapFromImage(img)
        self.SetMinSize((self._bmp.GetWidth(), self._bmp.GetHeight()))
618767
private static BufferedImage draw(BufferedImage backgroundImg, Image img, Rectangle rectangle, float alpha) {
		final Graphics2D g = backgroundImg.createGraphics();
		g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
		g.drawImage(img, rectangle.x, rectangle.y, rectangle.width, rectangle.height, null); // 绘制切割后的图
		g.dispose();
		return backgroundImg;
	}
795007
private static int getTrimmedWidth(BufferedImage img) {
    int height = img.getHeight();
    int width = img.getWidth();
    int trimmedWidth = 0;

    for (int i = 0; i < height; i++) {
      for (int j = width - 1; j >= 0; j--) {
        if (img.getRGB(j, i) != Color.WHITE.getRGB() && j > trimmedWidth) {
          trimmedWidth = j;
          break;
        }
      }
    }

    return trimmedWidth;
  }
710883
public static BufferedImage convertImageToARGB( Image image ) {
		if ( image instanceof BufferedImage && ((BufferedImage)image).getType() == BufferedImage.TYPE_INT_ARGB )
			return (BufferedImage)image;
		BufferedImage p = new BufferedImage( image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
		Graphics2D g = p.createGraphics();
		g.drawImage( image, 0, 0, null );
		g.dispose();
		return p;
	}
278977
public static void binary(Image srcImage, OutputStream out, String imageType) {
		binary(srcImage, getImageOutputStream(out), imageType);
	}