bufferedimage

Fast loading and drawing of RGB data in BufferedImage

廉价感情. 提交于 2019-11-27 10:23:44
问题 In some Java code running on Windows, I'm reading some large blocks of RGB data from disk and want to display this to screen as quickly as possible. The RGB data is 8 bits per channel without any alpha. Currently I have code like the following to create the BufferedImage. BufferedImage getBufferedImage(File file, int width, int height) { byte[] rgbData = readRGBFromFile(file); WritableRaster raster = Raster.createInterleavedRaster( rgbData, width, height, width * 3, // scanlineStride 3, //

BufferedImage in Android

耗尽温柔 提交于 2019-11-27 09:20:41
I've an app that takes a camera picture and saves on sdcard as jpeg. i want to distort the picture with a spherize filter. I can read the jpeg to a bitmap, but the code i have found that does the distortion distorts a bufferedimage. i understand that javax.imageio is not supported in android but is there a way of reading a jpeg into the memory as a bufferedimage? thanks mat. /* Copyright 2006 Jerry Huxtable Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache

Rotating an Image object

你。 提交于 2019-11-27 08:24:40
问题 I have a method getImage() that needs to rotate an Image , store it in a new variable, then return that new Image . Here is my attempt, the image appears to be empty or something. It just does not show up on the screen: public Image getImage() { buffImage.createGraphics().rotate(direction); return buffImage; } When I take out the buffImage.createGraphics().rotate(direction); the image draws on the screen just fine with no problems but of course, not rotated. 回答1: So, based on the example in

Java getSubimage() outside of raster

耗尽温柔 提交于 2019-11-27 08:08:15
问题 I'm trying to take an image and store it in an array of 16x16 subimages. The image I am using is 512x512 pixels. However, while iterating through the loop, getSubimage() is stopped by a Raster exception. Here is the code: public class TileList extends JPanel { private static final int width = 16; //width of a tile private static final int height = width; private int col = 1; private int row = 1; private BufferedImage image; File tilesetImage = new File("image.png"); BufferedImage tileset[];

Trying to load image using ImageIO.read(class.getResource(URL)) but getResource is returning null

自作多情 提交于 2019-11-27 08:02:06
问题 I've been making a 2D game with my buddy and I've been learning a lot about some basic game dev concepts through some Youtube tutorials. One of the things I was learning about is sprites (for those that don't know, 2D images to render to the screen) and how to use them in my game. I've been using ImageIO.read(this.class.getResource(pathToMySprite)) but it seems that getResource() is returning null for some reason. I've been screwing around with the path a little, adding "/" in front of it,

Removing transparency in PNG BufferedImage

大憨熊 提交于 2019-11-27 07:58:27
问题 I'm reading a PNG image with the following code: BufferedImage img = ImageIO.read(new URL(url)); Upon displaying it, there is a black background, which I know is caused from PNG transparency. I found solutions to this problem suggesting the use of BufferedImage.TYPE_INT_RGB , however I am unsure how to apply this to my code above. 回答1: Create a second BufferedImage of type TYPE_INT_RGB ... BufferedImage copy = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);

Why does ImageReader return incorrect BufferedImage?

走远了吗. 提交于 2019-11-27 07:49:17
问题 I'm trying to access a animated GIF image with 21 frames and then read the 12th (cause it starts at 0?) frame. import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.imageio.ImageIO; import javax.imageio.ImageReader; import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.IOFileFilter; import org.apache.commons.io.filefilter.SuffixFileFilter; import

How to draw part of a large BufferedImage?

柔情痞子 提交于 2019-11-27 07:48:51
问题 I have a 10000x10000 BufferedImage and I'm looking to draw only part of it to a Canvas , is there a way to do this using args such as: x, y, width, height ? So for example, drawImage(img, x, y, width, height) would draw a rectangle from the image starting at (x, y) and having (width, height) as the dimensions? EDIT: I'm going to re- word this question: I have a 10000x10000 image and I only want to display a portion of it on the screen, the problem with just offsetting it by x and y is that

BufferedImage to BMP in Java

◇◆丶佛笑我妖孽 提交于 2019-11-27 06:53:49
问题 I have a BufferedImage object and I want to encode it to the BMP format and save it to disk. How do I do this? In JPEG it's ok: BufferedImage img; //here is an image ready to be recorded into the hard disk FileOutputStream fout = new FileOutputStream("image.jpg"); JPEGImageEncoder jencoder = JPEGCodec.createJPEGEncoder(fout); JPEGEncodeParam enParam = jencoder.getDefaultJPEGEncodeParam(img); enParam.setQuality(1.0F, true); jencoder.setJPEGEncodeParam(enParam); jencoder.encode(img); fout.close

Change the alpha value of a BufferedImage?

二次信任 提交于 2019-11-27 06:49:22
问题 How do I change the global alpha value of a BufferedImage in Java? (I.E. make every pixel in the image that has a alpha value of 100 have a alpha value of 80) 回答1: I don't believe there's a single simple command to do this. A few options: copy into another image with an AlphaComposite specified (downside: not converted in place) directly manipulate the raster (downside: can lead to unmanaged images) use a filter or BufferedImageOp The first is the simplest to implement, IMO. 回答2: @Neil Coffey