Java examples for 2D Graphics:Image Convert
get Opaque Image
/*/*from w ww. j a va 2 s. c o m*/ * Copyright (C) 2012 Markus Niedermann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ //package com.java2s; import java.awt.Color; import java.awt.image.BufferedImage; public class Main { private static BufferedImage getOpaqueImage(final BufferedImage src, final Color col, final int opaqueLimit) { BufferedImage ret = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB); for (int y = 0; y < src.getHeight(); y++) { for (int x = 0; x < src.getWidth(); x++) { if (((src.getRGB(x, y) >> 24) & 0xff) > opaqueLimit) { ret.setRGB(x, y, col.getRGB()); } } } return ret; } }