Java Code Examples for java.awt.image.BufferedImage.TYPE_4BYTE_ABGR

The following are Jave code examples for showing how to use TYPE_4BYTE_ABGR of the java.awt.image.BufferedImage class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: sentry   File: ColorThief.java   View Source Code Vote up 6 votes
/**
 * Use the median cut algorithm to cluster similar colors.
 *
 * @param sourceImage the source image
 * @param colorCount  the size of the palette; the number of colors returned
 * @param quality     0 is the highest quality settings. 10 is the default. There is
 *                    a trade-off between quality and speed. The bigger the number,
 *                    the faster the palette generation but the greater the
 *                    likelihood that colors will be missed.
 * @param ignoreWhite if <code>true</code>, white pixels are ignored
 * @return the color map
 */
public static CMap getColorMap(
    BufferedImage sourceImage,
    int colorCount,
    int quality,
    boolean ignoreWhite) {
    int[][] pixelArray;

    switch (sourceImage.getType()) {
        case BufferedImage.TYPE_3BYTE_BGR:
        case BufferedImage.TYPE_4BYTE_ABGR:
            pixelArray = getPixelsFast(sourceImage, quality, ignoreWhite);
            break;

        default:
            pixelArray = getPixelsSlow(sourceImage, quality, ignoreWhite);
    }

    // Send array to quantize function which clusters values using median
    // cut algorithm
    CMap cmap = MMCQ.quantize(pixelArray, colorCount);
    return cmap;
}
 
Example 2
Project: rapidminer   File: Tools.java   View Source Code Vote up 6 votes
public static ImageIcon getSmallSystemIcon(Image img) throws Exception {
	if (img.getWidth(null) > 20 || img.getHeight(null) > 20) {
		if (img.getWidth(null) > img.getHeight(null)) {
			width = 18;
			height = img.getHeight(null) * 18 / img.getWidth(null);
		} else {
			height = 18;
			width = img.getWidth(null) * 18 / img.getHeight(null);
		}
	} else {
		return new ImageIcon(img);
	}

	dest = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
	dest2 = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);

	g = dest.getGraphics();
	g.drawImage(img, 1, 1, width, height, null);

	g.dispose();

	blurOperator.filter(dest, dest2);

	return new ImageIcon(dest2);
}
 
Example 3
Project: sumo   File: SVGImageFactory.java   View Source Code Vote up 6 votes
public static BufferedImage createSVGImage(String filename, int width, int height) throws Exception
{
	File file = new File(filename);
	FileInputStream fis = new FileInputStream(file);
	SVGUniverse universe = new SVGUniverse();
	universe.loadSVG(fis, file.toURI().toString());
	SVGDiagram diagram = universe.getDiagram(file.toURI());
	diagram.setIgnoringClipHeuristic(true);
	BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
	Graphics2D g = image.createGraphics();
	g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	g.transform(getAffineTransform((int)diagram.getWidth(), (int)diagram.getHeight(), width, height));
	diagram.render(g);
	g.dispose();
	return image;
}
 
Example 4
Project: jmt   File: DefaultIconsToolkit.java   View Source Code Vote up 6 votes
@Override
public Image getEdgeIcon(Rectangle bounds, Point[] anglePoints) {
	/*creates background image.*/
	BufferedImage bgImage = new BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_4BYTE_ABGR);
	Graphics bgGr = bgImage.getGraphics();
	bgGr.setColor(new Color(0, 0, 0, 0));
	bgGr.fillRect(0, 0, bounds.width, bounds.height);
	for (int i = 0; i < anglePoints.length - 1; i++) {
		//Must convert absolute coords to local coords
		int x0 = anglePoints[i].x - bounds.x, y0 = anglePoints[i].y - bounds.y, x1 = anglePoints[i + 1].x - bounds.x, y1 = anglePoints[i + 1].y
				- bounds.y;
		bgGr.setColor(Color.GRAY);
		bgGr.drawLine(x0, y0, x1, y1);
		bgGr.setColor(new Color(30, 30, 30, 30));
		//bgGr.fillRect(Math.min(x0,x1)-1, Math.min(y0,y1)-1, Math.abs(x1-x0)+3, Math.abs(y1-y0)+3);
		bgGr.drawLine(x0 - 1, y0 - 1, x1 - 1, y1 - 1);
	}
	return bgImage;
}
 
Example 5
Project: openjdk-jdk10   File: OpCompatibleImageTest.java   View Source Code Vote up 6 votes
private static String describeType(int type) {
    switch(type) {
    case BufferedImage.TYPE_3BYTE_BGR:
        return "TYPE_3BYTE_BGR";
    case BufferedImage.TYPE_4BYTE_ABGR:
        return "TYPE_4BYTE_ABGR";
    case BufferedImage.TYPE_BYTE_GRAY:
        return "TYPE_BYTE_GRAY";
    case BufferedImage.TYPE_INT_ARGB:
        return "TYPE_INT_ARGB";
    case BufferedImage.TYPE_INT_BGR:
        return  "TYPE_INT_BGR";
    case BufferedImage.TYPE_INT_RGB:
        return "TYPE_INT_RGB";
    case BufferedImage.TYPE_BYTE_INDEXED:
        return "TYPE_BYTE_INDEXED";
    default:
        throw new RuntimeException("Test FAILED: unknown type " + type);
    }
}
 
Example 6
Project: ALTTPMenuPractice   File: PlayerMovement.java   View Source Code Vote up 5 votes
public static BufferedImage drawOptimalPath(PlayerMovement[] moves, boolean includeGoal) {
	BufferedImage ret = new BufferedImage(BG_WIDTH, BG_HEIGHT, BufferedImage.TYPE_4BYTE_ABGR);
	Graphics g = ret.getGraphics();
	int size = moves.length + (includeGoal ? 0 : -1);
	for (int i = 0; i < size; i++) {
		PlayerMovement p = moves[i];
		ItemPoint cursorLoc = ItemPoint.valueOf("SLOT_" + p.LOCATION);
		g.drawImage(OPTIMAL_MOVES[p.MOVEMENT],
				ITEM_ORIGIN_X + cursorLoc.x - CURSOR_OFFSET,
				ITEM_ORIGIN_Y + cursorLoc.y - CURSOR_OFFSET,
				null);
	}
	return ret;
}
 
Example 7
Project: Explorium   File: TextureGenerator.java   View Source Code Vote up 5 votes
public static BufferedImage generateButtonTexture(Color a,int w,int h,double seed) {
	BufferedImage bi = new BufferedImage(w,h, BufferedImage.TYPE_4BYTE_ABGR);
	Color c;
	for(int i = 0;i < bi.getWidth();i++) {
		for(int j = 0;j < bi.getHeight();j++) {
			c = TextureGenerator.trick(a,VMath.noise(i/12. + .1, j/2. + .1, seed + .1)*60);
			bi.setRGB(i, j, c.getRGB());
		}
	}
	return bi;
}
 
Example 8
Project: QN-ACTR-Release   File: QueueNetAnimation.java   View Source Code Vote up 5 votes
private void buildBGImage() {
	int tileX = 30, tileY = 25;
	Image tile = iconToolkit.getBGTileIcon(new Rectangle(tileX, tileY));
	bgImage = new BufferedImage(getSize().width, getSize().height, BufferedImage.TYPE_4BYTE_ABGR);
	Graphics g = bgImage.getGraphics();
	for (int i = 0; i * tileX < getSize().width; i++) {
		for (int j = 0; j * tileY < getSize().height; j++) {
			g.drawImage(tile, i * tileX, j * tileY, this);
		}
	}
}
 
Example 9
Project: ocraft-s2client   File: ImageData.java   View Source Code Vote up 5 votes
private int tryGetImageType() {
    switch (bitsPerPixel) {
        case 1:
            return BufferedImage.TYPE_BYTE_BINARY;
        case 8:
            return BufferedImage.TYPE_BYTE_GRAY;
        case 32:
            return BufferedImage.TYPE_4BYTE_ABGR;
        default:
            throw new IllegalArgumentException(
                    format("Unsupported image type with bits per pixel [%d]. Expected {1, 8, 32}.", bitsPerPixel));
    }
}
 
Example 10
Project: Explorium   File: BlockDoor.java   View Source Code Vote up 5 votes
@Override
public BufferedImage getTexture(double seed) {
	mainColor = new Color(133,94,66);
	BufferedImage bi = new BufferedImage(TextureGenerator.TEX_W, TextureGenerator.TEX_H, BufferedImage.TYPE_4BYTE_ABGR);
	Color c;
	for(int i = 0;i < bi.getWidth();i++) {
		for(int j = 0;j < bi.getHeight();j++) {
			c = TextureGenerator.fade(TextureGenerator.trick(mainColor, -30),mainColor,Math.abs(VMath.mod(i,16)-16)/16);
			//strength != 0 && weakStrength != 0 ? trick(mainc,turbulence(i+3.1f,j+3.1f,1,seed)*80) : mainc;
			bi.setRGB(i, j, c.getRGB());
		}
	}
	return bi;
}
 
Example 11
Project: QN-ACTR-Release   File: DefaultIconsToolkit.java   View Source Code Vote up 5 votes
@Override
public Image getJobIcon(Rectangle bounds) {
	int width = 100, height = 100;
	BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
	Graphics g = bi.getGraphics();
	g.setColor(new Color(0, 0, 0, 50));
	g.fillOval(0, 0, width, height);
	for (int i = 0, monoChannel = 0; i < 10; i++, monoChannel = (int) ((1 - Math.exp(-i * 0.5)) * 255)) {
		g.setColor(new Color(monoChannel, monoChannel, monoChannel, 255));
		int r = (int) Math.pow(i, 1.5), s = (int) (r * 2.9);
		g.fillOval(r, r, width - s, height - s);
	}
	return bi.getScaledInstance(bounds.width, bounds.height, Image.SCALE_SMOOTH);
}
 
Example 12
Project: QN-ACTR-Release   File: SampleQNAnimation.java   View Source Code Vote up 5 votes
@Override
public Image getBGTileIcon(Rectangle bounds) {
	BufferedImage bi = new BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_4BYTE_ABGR);
	Graphics g = bi.getGraphics();
	g.setColor(new Color(150, 150, 150, 200));
	g.fillRect(0, 0, bounds.width, bounds.height);
	return bi;
}
 
Example 13
Project: jmt   File: QueueNetAnimation.java   View Source Code Vote up 5 votes
private void buildBGImage() {
	int tileX = 30, tileY = 25;
	Image tile = iconToolkit.getBGTileIcon(new Rectangle(tileX, tileY));
	bgImage = new BufferedImage(getSize().width, getSize().height, BufferedImage.TYPE_4BYTE_ABGR);
	Graphics g = bgImage.getGraphics();
	for (int i = 0; i * tileX < getSize().width; i++) {
		for (int j = 0; j * tileY < getSize().height; j++) {
			g.drawImage(tile, i * tileX, j * tileY, this);
		}
	}
}
 
Example 14
Project: jmt   File: DefaultIconsToolkit.java   View Source Code Vote up 5 votes
@Override
public Image getBGTileIcon(Rectangle bounds) {
	BufferedImage bi = new BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_4BYTE_ABGR);
	Graphics g = bi.getGraphics();
	g.setColor(Color.WHITE);
	g.fillRect(0, 0, bounds.width, bounds.height);
	g.setColor(Color.GRAY);
	g.fillRect(0, 0, 1, 1);
	return bi;
}
 
Example 15
Project: GazePlay   File: HeatChart.java   View Source Code Vote up 5 votes
/**
 * Generates and returns a new chart <code>Image</code> configured according to this object's currently held
 * settings. The given parameter determines whether transparency should be enabled for the generated images.
 * 
 * <p>
 * No chart will be generated until this or the related <code>saveToFile(File)</code> method are called. All
 * successive calls will result in the generation of a new chart images, no caching is used.
 * 
 * @param alpha
 *            whether to enable transparency.
 * @return A newly generated chart <code>Image</code>. The returned images is a <code>BufferedImage</code>.
 */
public Image getChartImage(boolean alpha) {
    // Calculate all unknown dimensions.
    measureComponents();
    updateCoordinates();

    // Determine images type based upon whether require alpha or not.
    // Using BufferedImage.TYPE_INT_ARGB seems to break on jpg.
    int imageType = (alpha ? BufferedImage.TYPE_4BYTE_ABGR : BufferedImage.TYPE_3BYTE_BGR);

    // Create our chart images which we will eventually draw everything on.
    BufferedImage chartImage = new BufferedImage(chartSize.width, chartSize.height, imageType);
    Graphics2D chartGraphics = chartImage.createGraphics();

    // Use anti-aliasing where ever possible.
    chartGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Set the background.
    chartGraphics.setColor(backgroundColour);
    chartGraphics.fillRect(0, 0, chartSize.width, chartSize.height);

    // Draw the title.
    drawTitle(chartGraphics);

    // Draw the heatmap images.
    drawHeatMap(chartGraphics, zValues);

    // Draw the axis labels.
    drawXLabel(chartGraphics);
    drawYLabel(chartGraphics);

    // Draw the axis bars.
    drawAxisBars(chartGraphics);

    // Draw axis values.
    drawXValues(chartGraphics);
    drawYValues(chartGraphics);

    return chartImage;
}
 
Example 16
Project: jdk8u-jdk   File: ColConvTest.java   View Source Code Vote up 5 votes
static String getImageTypeName(int type) {
    switch(type) {
        case BufferedImage.TYPE_INT_ARGB:
            return "TYPE_INT_ARGB";
        case BufferedImage.TYPE_INT_RGB:
            return "TYPE_INT_RGB";
        case BufferedImage.TYPE_INT_BGR:
            return "TYPE_INT_BGR";
        case BufferedImage.TYPE_INT_ARGB_PRE:
            return "TYPE_INT_ARGB_PRE";
        case BufferedImage.TYPE_3BYTE_BGR:
            return "TYPE_3BYTE_BGR";
        case BufferedImage.TYPE_4BYTE_ABGR:
            return "TYPE_4BYTE_ABGR";
        case BufferedImage.TYPE_4BYTE_ABGR_PRE:
            return "TYPE_4BYTE_ABGR_PRE";
        case BufferedImage.TYPE_BYTE_BINARY:
            return "TYPE_BYTE_BINARY";
        case BufferedImage.TYPE_BYTE_GRAY:
            return "TYPE_BYTE_GRAY";
        case BufferedImage.TYPE_BYTE_INDEXED:
            return "TYPE_BYTE_INDEXED";
        case BufferedImage.TYPE_USHORT_555_RGB:
            return "TYPE_USHORT_555_RGB";
        case BufferedImage.TYPE_USHORT_565_RGB:
            return "TYPE_USHORT_565_RGB";
        case BufferedImage.TYPE_USHORT_GRAY:
            return "TYPE_USHORT_GRAY";
    }
    return "UNKNOWN";
}
 
Example 17
Project: Pixie   File: Utils.java   View Source Code Vote up 5 votes
/**
 * Copy one buffered image to another and return the copied image.
 *
 * @param src - source image
 * @return - the copied image of the original
 */
public static BufferedImage createImageCopy(final BufferedImage src) {
    BufferedImage dst = new BufferedImage(src.getWidth(), src.getHeight(), src.getType());

    byte[] srcBuf = getByteData(src);
    byte[] dstBuf = getByteData(dst);
    int representationFactor;

    // width * hight * 3 because of rgb components and byte representation
    switch (src.getType()) {
        case BufferedImage.TYPE_BYTE_GRAY:
            representationFactor = 1;
            break;
        case BufferedImage.TYPE_3BYTE_BGR:
            representationFactor = 3;
            break;
        case BufferedImage.TYPE_4BYTE_ABGR:
            representationFactor = 4;
            break;
        default:
            representationFactor = 3;
            break;
    }

    System.arraycopy(srcBuf, 0, dstBuf, 0, src.getWidth() * src.getHeight() * representationFactor);

    return dst;
}
 
Example 18
Project: openjdk-jdk10   File: Destinations.java   View Source Code Vote up 4 votes
public static void init() {
    destroot = new Group.EnableSet(TestEnvironment.globaloptroot,
                                   "dest", "Output Destination Options");

    new Screen();
    new OffScreen();

    if (GraphicsTests.hasGraphics2D) {
        if (ImageTests.hasCompatImage) {
            compatimgdestroot =
                new Group.EnableSet(destroot, "compatimg",
                                    "Compatible Image Destinations");
            compatimgdestroot.setHorizontal();

            new CompatImg();
            new CompatImg(Transparency.OPAQUE);
            new CompatImg(Transparency.BITMASK);
            new CompatImg(Transparency.TRANSLUCENT);
        }

        if (ImageTests.hasVolatileImage) {
            volimgdestroot = new Group.EnableSet(destroot, "volimg",
                    "Output to Volatile Image");

            volimgdestroot.setHorizontal();
            new VolatileImg();
            if (ImageTests.hasTransparentVolatileImage) {
                new VolatileImg(Transparency.OPAQUE);
                new VolatileImg(Transparency.BITMASK);
                new VolatileImg(Transparency.TRANSLUCENT);
            }
        }

        bufimgdestroot = new Group.EnableSet(destroot, "bufimg",
                                             "BufferedImage Destinations");

        new BufImg(BufferedImage.TYPE_INT_RGB);
        new BufImg(BufferedImage.TYPE_INT_ARGB);
        new BufImg(BufferedImage.TYPE_INT_ARGB_PRE);
        new BufImg(BufferedImage.TYPE_3BYTE_BGR);
        new BufImg(BufferedImage.TYPE_BYTE_INDEXED);
        new BufImg(BufferedImage.TYPE_BYTE_GRAY);
        new BufImg(BufferedImage.TYPE_4BYTE_ABGR);
        new BufImg(BufferedImage.TYPE_4BYTE_ABGR_PRE);
        new CustomImg();
    }
}
 
Example 19
Project: incubator-netbeans   File: SceneExporter.java   View Source Code Vote up 4 votes
/**
 * Takes the Scene and writes an image file according to the constraints 
 * defined by the caller. This returns a BufferedImage of the Scene even if 
 * the file can not be written.
 * @param scene The Scene to be exported as an image.
 * @param file The file used to store the exported image. If null, then it is 
 * assumed that the raw image is to be returned only and not written to a file.
 * @param SceneExporter.ImageType The image type to be exported for the image map.
 * @param SceneExporter.ZoomType Defines the strategy
 * by which to set the exporting scale factor. Note that certain parameters are
 * nullified by the choice of ZoomType. For instance, if ZoomType.CUSTOM_SIZE is
 * not chosen, then the width and height parameters are not used.
 * @param visibleAreaOnly Eliminates all zoom features. If true, the exported
 * image will be a created from the visible area of the scene.
 * @param selectedOnly Create an image including only the objects selected on
 * the scene. Note that this feature requires that the scene is an instance of
 * an ObjectScene since it is the implementation that allows for object selection.
 * @param quality And integer value between 0-100. This is for JPG images only. Parameter is not used if
 * an image type other than jpg is selected.
 * @param width Directly sets the horizontal dimension of the exported image.
 * This is only used when the zoomType is ZoomType.CUSTOM_SIZE
 * @param height Directly sets the vertical dimension of the exported image.
 * This is only used when the zoomType is ZoomType.CUSTOM_SIZE.
 * @return image The raw image that was written to the file.
 * @throws java.io.IOException If for some reason the file cannot be written, 
 * an IOExeption will be thrown.
 */
public static BufferedImage createImage(Scene scene, File file, ImageType imageType, ZoomType zoomType,
        boolean visibleAreaOnly,
        boolean selectedOnly,
        int quality,
        int width,
        int height) throws IOException {

    if (scene == null) {
        return null;
    }
    if (!scene.isValidated()) {
        if (scene.getView() != null) {
            scene.validate();
        } else {
            BufferedImage emptyImage = new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR);
            Graphics2D emptyGraphics = emptyImage.createGraphics();
            scene.validate(emptyGraphics);
        }
    }
    Scene2Image s2i = new Scene2Image(scene, file);
    BufferedImage image = s2i.createImage(imageType, zoomType, visibleAreaOnly, selectedOnly, quality, width, height, false);

    return image;
}
 
Example 20
Project: CGL   File: Texture.java   View Source Code Vote up 4 votes
/**
 * Analyes the specified image and sets the proper openGLImage-values.
 * @return <code>true</code> if the image foramt has successfully detected.
 */
public boolean analyseAndSetOpenGLParameters() {
	boolean retValue = true;
	String errorString = "";

	try {
		switch(image.getType()) {
		case BufferedImage.TYPE_4BYTE_ABGR:
			openGLImageFormat= GL2.GL_RGBA;
			openGLImageType  = GL2.GL_UNSIGNED_INT_8_8_8_8; // OK!
			openGLImageInternalFormat = GL2.GL_RGBA;
			break;

		case BufferedImage.TYPE_3BYTE_BGR:
			openGLImageFormat= GL2.GL_BGR;
			openGLImageType  = GL2.GL_UNSIGNED_BYTE;
			openGLImageInternalFormat = GL2.GL_RGB;
			break;

		case BufferedImage.TYPE_BYTE_GRAY:
			openGLImageFormat= GL2.GL_LUMINANCE;
			openGLImageType  = GL2.GL_UNSIGNED_BYTE;
			openGLImageInternalFormat = GL2.GL_LUMINANCE;
			break;
		case BufferedImage.TYPE_CUSTOM:
			ColorModel colorModel = image.getColorModel();
			ColorSpace colorSpace = colorModel.getColorSpace();
			if(colorSpace.getType()==ColorSpace.TYPE_GRAY) {
				if(colorModel.hasAlpha()==true) {
					openGLImageFormat= GL2.GL_LUMINANCE_ALPHA;
					openGLImageType  = GL2.GL_UNSIGNED_BYTE;
					openGLImageInternalFormat = GL2.GL_LUMINANCE_ALPHA;
				}
				else {
					openGLImageFormat= GL2.GL_LUMINANCE;
					openGLImageType  = GL2.GL_UNSIGNED_BYTE;
					openGLImageInternalFormat = GL2.GL_LUMINANCE;
				}
			}
			else {
				errorString = "Unsupported image format."+
						"\nURL="+textureBaseURL+textureURL+"\n";
				retValue = false;
			}
			break;
		}
	}
	catch(Throwable t) {
		errorString = "Exception during image analyzing."+
				"\nURL="+textureBaseURL+textureURL+"\n"+t.getMessage();
		retValue = false;
	}

	if(!errorString.isEmpty()){
		StatusPrinter.print("ERROR", errorString, Texture.class);
	}
	return retValue;
}