本文整理汇总了Java中java.awt.image.PixelGrabber.getHeight方法的典型用法代码示例。如果您正苦于以下问题:Java PixelGrabber.getHeight方法的具体用法?Java PixelGrabber.getHeight怎么用?Java PixelGrabber.getHeight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.PixelGrabber
的用法示例。
在下文中一共展示了PixelGrabber.getHeight方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getImageToWrite
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
/**
* Get the image to write. This is the mosaic image with alpha channel stripped, as this
* doesn't work with the JPEG export.
*/
private BufferedImage getImageToWrite() throws InterruptedException {
BufferedImage image = SwingFXUtils.fromFXImage(mainController.getMosaicImage(), null);
final int[] RGB_MASKS = {0xFF0000, 0xFF00, 0xFF};
final ColorModel rgbOpaque = new DirectColorModel(32, RGB_MASKS[0], RGB_MASKS[1], RGB_MASKS[2]);
PixelGrabber pg = new PixelGrabber(image, 0, 0, -1, -1, true);
pg.grabPixels();
int width = pg.getWidth(), height = pg.getHeight();
DataBuffer buffer = new DataBufferInt((int[]) pg.getPixels(), pg.getWidth() * pg.getHeight());
WritableRaster raster = Raster.createPackedRaster(buffer, width, height, width, RGB_MASKS, null);
BufferedImage bi = new BufferedImage(rgbOpaque, raster, false, null);
return bi;
}
示例2: createImage
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
/**
* Cretae a BufferedImage from an ImageProducer.
* @param producer the ImageProducer
* @return a new TYPE_INT_ARGB BufferedImage
*/
public static BufferedImage createImage(ImageProducer producer) {
PixelGrabber pg = new PixelGrabber(producer, 0, 0, -1, -1, null, 0, 0);
try {
pg.grabPixels();
} catch (InterruptedException e) {
throw new RuntimeException("Image fetch interrupted");
}
if ((pg.status() & ImageObserver.ABORT) != 0)
throw new RuntimeException("Image fetch aborted");
if ((pg.status() & ImageObserver.ERROR) != 0)
throw new RuntimeException("Image fetch error");
BufferedImage p = new BufferedImage(pg.getWidth(), pg.getHeight(), BufferedImage.TYPE_INT_ARGB);
p.setRGB(0, 0, pg.getWidth(), pg.getHeight(), (int[])pg.getPixels(), 0, pg.getWidth());
return p;
}
示例3: createImage
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
/**
* Cretae a BufferedImage from an ImageProducer.
* @param producer the ImageProducer
* @return a new TYPE_INT_ARGB BufferedImage
*/
public static BufferedImage createImage(ImageProducer producer) {
PixelGrabber pg = new PixelGrabber(producer, 0, 0, -1, -1, null, 0, 0);
try {
pg.grabPixels();
} catch (InterruptedException e) {
throw new RuntimeException("Image fetch interrupted");
}
if ((pg.status() & ImageObserver.ABORT) != 0) {
throw new RuntimeException("Image fetch aborted");
}
if ((pg.status() & ImageObserver.ERROR) != 0) {
throw new RuntimeException("Image fetch error");
}
BufferedImage p = new BufferedImage(pg.getWidth(), pg.getHeight(), BufferedImage.TYPE_INT_ARGB);
p.setRGB(0, 0, pg.getWidth(), pg.getHeight(), (int[])pg.getPixels(), 0, pg.getWidth());
return p;
}
示例4: init
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
private void init(Image image)
{
PixelGrabber pixelGrabber = ImageUtil.getPixelGrabber(image, location);
width = pixelGrabber.getWidth();
height = pixelGrabber.getHeight();
Object p = pixelGrabber.getPixels();
if (p != null)
{
Class ct = p.getClass().getComponentType();
if (ct != null)
{
if (ct.equals(Integer.TYPE))
pixels = (int[])p;
else if (ct.equals(Byte.TYPE))
throw new IllegalStateException("int[] of pixels expected, received byte[] instead.");
}
}
}
示例5: initialize
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
/**
* Initialize all the structures and parameters.
*
* @throws Exception
*/
public void initialize() throws Exception {
if (originalImage == null) {
throw new Exception("Cannot segment a NULL image.");
}
// Region border thickness.
borderThickness = 0;
pg = new PixelGrabber(originalImage, 0, 0, -1, -1, true);
try {
pg.grabPixels();
} catch (InterruptedException e) {
System.err.println(e.getMessage());
}
width = pg.getWidth();
height = pg.getHeight();
imageRaster = (int[]) pg.getPixels();
aspectRatio = (double) height / (double) width;
numPixels = width * height;
// Algorithm-specific thresholds.
logdelta = 2.0 * Math.log(6.0 * numPixels);
// Small regions are those that contain less than 0.1% of image pixels.
smallRegionSize = (int) (0.001 * numPixels);
}
示例6: convert
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
private FloatArray2D convert(java.awt.Image img) {
FloatArray2D image;
PixelGrabber grabber = new PixelGrabber(img, 0, 0, -1, -1, true);
try {
grabber.grabPixels();
} catch (Exception e) {
throw new RuntimeException(e);
}
int[] data = (int[]) grabber.getPixels();
image = new FloatArray2D(grabber.getWidth(), grabber.getHeight());
for (int d = 0; d < data.length; d++)
image.data[d] = normTo1(RGB2Grey(data[d]));
return image;
}
示例7: DirectGif89Frame
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
DirectGif89Frame(Image img) throws IOException {
PixelGrabber pg = new PixelGrabber(img, 0, 0, -1, -1, true);
String errmsg = null;
try {
if (!pg.grabPixels()) {
errmsg = "can't grab pixels from image";
}
}
catch (InterruptedException e) {
errmsg = "interrupted grabbing pixels from image";
}
if (errmsg != null) {
throw new IOException(errmsg + " (" + getClass().getName() + ")");
}
theWidth = pg.getWidth();
theHeight = pg.getHeight();
argbPixels = (int[]) pg.getPixels();
ciPixels = new byte[argbPixels.length];
}
示例8: getBufferedImageFromPixelGrabber
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
/**
* Return a BufferedImage loaded from a Image, using a PixelGrabber. Good
* for when you have an Image, not a BufferedImage, and don't know the width
* and height. There is a performance penalty with this method, though.
*
* @param image the source Image
* @param x x start pixel - the horizontal pixel location in the returned
* image that the provided image will be set.
* @param y y start pixel - the vertical pixel location in the returned
* image that the provided image will be set.
* @param w crop width (-1 uses image width)
* @param h crop height (-1 uses image height)
* @param imageType the image color model. See BufferedImage.
* @return BufferedImage if it can be created, null if anything goes wrong.
*/
public static BufferedImage getBufferedImageFromPixelGrabber(Image image, int x, int y, int w, int h, int imageType) {
PixelGrabber pg = new PixelGrabber(image, x, y, w, h, true);
int[] pixels = ImageHelper.grabPixels(pg);
if (pixels == null) {
return null;
}
w = pg.getWidth();
h = pg.getHeight();
pg = null;
BufferedImage bi = new BufferedImage(w, h, imageType);
logger.fine("BufferedImageHelper.getBufferedImage(): Got buffered image...");
// bi.setRGB(0, 0, w, h, pixels, 0, w);
/**
* Looking at the standard BufferedImage code, an int[0] is allocated
* for every pixel. Maybe the memory usage is optimized for that, but it
* goes through a call stack for every pixel to do it. Let's just cycle
* through the data and write the pixels directly into the raster.
*/
WritableRaster raster = (WritableRaster) bi.getRaster();
raster.setDataElements(0, 0, w, h, pixels);
logger.fine("BufferedImageHelper.getBufferedImage(): set pixels in image...");
return bi;
}
示例9: getSplitImages
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
/**
* 分割指定图像为image[]
*
* @param image
* @param row
* @param col
* @return
*/
public static Image[] getSplitImages(Image image, int row, int col, boolean isFiltrate) {
int index = 0;
int wlength = image.getWidth(null) / row;
int hlength = image.getHeight(null) / col;
int l = wlength * hlength;
Image[] abufferedimage = new Image[l];
for (int y = 0; y < hlength; y++) {
for (int x = 0; x < wlength; x++) {
abufferedimage[index] = GraphicsUtils.createImage(row, col, true);
Graphics g = abufferedimage[index].getGraphics();
g.drawImage(image, 0, 0, row, col, (x * row), (y * col), row + (x * row), col + (y * col), null);
g.dispose();
g = null;
PixelGrabber pgr = new PixelGrabber(abufferedimage[index], 0, 0, -1, -1, true);
try {
pgr.grabPixels();
} catch (InterruptedException ex) {
}
int pixels[] = (int[]) pgr.getPixels();
if (isFiltrate) {
for (int i = 0; i < pixels.length; i++) {
int[] rgbs = LColor.getRGBs(pixels[i]);
if ((rgbs[0] == 247 && rgbs[1] == 0 && rgbs[2] == 255)
|| (rgbs[0] == 255 && rgbs[1] == 255 && rgbs[2] == 255)) {
pixels[i] = 0;
}
}
}
ImageProducer ip = new MemoryImageSource(pgr.getWidth(), pgr.getHeight(), pixels, 0, pgr.getWidth());
abufferedimage[index] = toolKit.createImage(ip);
index++;
}
}
return abufferedimage;
}
示例10: getSplit2Images
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
/**
* 分割指定图像为image[]
*
* @param image
* @param row
* @param col
* @return
*/
public static Image[][] getSplit2Images(Image image, int row, int col, boolean isFiltrate) {
int wlength = image.getWidth(null) / row;
int hlength = image.getHeight(null) / col;
Image[][] abufferedimage = new Image[wlength][hlength];
for (int y = 0; y < hlength; y++) {
for (int x = 0; x < wlength; x++) {
abufferedimage[x][y] = GraphicsUtils.createImage(row, col, true);
Graphics g = abufferedimage[x][y].getGraphics();
g.drawImage(image, 0, 0, row, col, (x * row), (y * col), row + (x * row), col + (y * col), null);
g.dispose();
g = null;
PixelGrabber pgr = new PixelGrabber(abufferedimage[x][y], 0, 0, -1, -1, true);
try {
pgr.grabPixels();
} catch (InterruptedException ex) {
ex.getStackTrace();
}
int pixels[] = (int[]) pgr.getPixels();
if (isFiltrate) {
for (int i = 0; i < pixels.length; i++) {
int[] rgbs = LColor.getRGBs(pixels[i]);
if ((rgbs[0] == 247 && rgbs[1] == 0 && rgbs[2] == 255)
|| (rgbs[0] == 255 && rgbs[1] == 0 && rgbs[2] == 255)
|| (rgbs[0] == 0 && rgbs[1] == 0 && rgbs[2] == 0)) {
pixels[i] = 0;
}
}
}
ImageProducer ip = new MemoryImageSource(pgr.getWidth(), pgr.getHeight(), pixels, 0, pgr.getWidth());
abufferedimage[x][y] = toolKit.createImage(ip);
}
}
return abufferedimage;
}
示例11: BmpWriter
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
/**
* The constructor.
*
* @param img
*/
public BmpWriter( Image img )
{
if ( img == null )
{
return;
}
PixelGrabber pg = new PixelGrabber( img, 0, 0, -1, -1, true );
try
{
pg.grabPixels( );
}
catch ( InterruptedException e )
{
return;
}
if ( ( pg.status( ) & ImageObserver.ABORT ) != 0 )
{
return;
}
this.pix = (int[]) pg.getPixels( );
this.width = pg.getWidth( );
this.height = pg.getHeight( );
}
示例12: init
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
private void init(Image image)
{
PixelGrabber pixelGrabber = ImageUtil.getPixelGrabber(image, location);
width = pixelGrabber.getWidth();
height = pixelGrabber.getHeight();
}
示例13: makeObject
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
public static AnimationHelper makeObject(String fileName, int tileWidth, int tileHeight, Color col) {
String key = fileName.trim().toLowerCase();
AnimationHelper animation = (AnimationHelper) animations.get(key);
if (animation == null) {
Image image = GraphicsUtils.loadNotCacheImage(fileName);
int c = col.getRGB();
int wlength = image.getWidth(null) / tileWidth;
int hlength = image.getHeight(null) / tileHeight;
Image[][] images = new Image[wlength][hlength];
for (int y = 0; y < hlength; y++) {
for (int x = 0; x < wlength; x++) {
images[x][y] = GraphicsUtils.createImage(tileWidth, tileHeight, true);
Graphics g = images[x][y].getGraphics();
g.drawImage(image, 0, 0, tileWidth, tileHeight, (x * tileWidth), (y * tileHeight),
tileWidth + (x * tileWidth), tileHeight + (y * tileHeight), null);
g.dispose();
g = null;
PixelGrabber pgr = new PixelGrabber(images[x][y], 0, 0, -1, -1, true);
try {
pgr.grabPixels();
} catch (InterruptedException ex) {
ex.getStackTrace();
}
int pixels[] = (int[]) pgr.getPixels();
for (int i = 0; i < pixels.length; i++) {
if (pixels[i] == c) {
pixels[i] = 0;
}
}
ImageProducer ip = new MemoryImageSource(pgr.getWidth(), pgr.getHeight(), pixels, 0,
pgr.getWidth());
images[x][y] = GraphicsUtils.toolKit.createImage(ip);
}
}
Image[][] result = new Image[hlength][wlength];
for (int y = 0; y < wlength; y++) {
for (int x = 0; x < hlength; x++) {
result[x][y] = images[y][x];
}
}
images = null;
animations.put(key, animation = makeObject(result[0], result[1], result[3], result[2]));
}
return animation;
}