本文整理汇总了Java中java.awt.image.PixelGrabber.grabPixels方法的典型用法代码示例。如果您正苦于以下问题:Java PixelGrabber.grabPixels方法的具体用法?Java PixelGrabber.grabPixels怎么用?Java PixelGrabber.grabPixels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.PixelGrabber
的用法示例。
在下文中一共展示了PixelGrabber.grabPixels方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getGTKProfilerResultsBackground
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
private static Color getGTKProfilerResultsBackground() {
int[] pixels = new int[1];
pixels[0] = -1;
// Prepare textarea to grab the color from
JTextArea textArea = new JTextArea();
textArea.setSize(new Dimension(10, 10));
textArea.doLayout();
// Print the textarea to an image
Image image = new BufferedImage(textArea.getSize().width, textArea.getSize().height, BufferedImage.TYPE_INT_RGB);
textArea.printAll(image.getGraphics());
// Grab appropriate pixels to get the color
PixelGrabber pixelGrabber = new PixelGrabber(image, 5, 5, 1, 1, pixels, 0, 1);
try {
pixelGrabber.grabPixels();
if (pixels[0] == -1) return Color.WHITE; // System background not customized
} catch (InterruptedException e) {
return getNonGTKProfilerResultsBackground();
}
return pixels[0] != -1 ? new Color(pixels[0]) : getNonGTKProfilerResultsBackground();
}
示例2: getOffscreenEquivalent
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
/**
* For the given input color, return the color that this color
* will map to in an offscreen image created by the given Component
*/
public static int getOffscreenEquivalent(int color, Component obs) {
Image im = obs.createImage(1, 1);
Graphics2D g = (Graphics2D) im.getGraphics();
g.setColor(new java.awt.Color(color));
g.fillRect(0, 0, 1, 1);
g.dispose();
int[] bg = new int[1];
PixelGrabber pg = new PixelGrabber(im, 0, 0, 1, 1, bg, 0, 1);
try {
pg.grabPixels();
}
catch (InterruptedException ex) {
logger.error("", ex);
}
return bg[0];
}
示例3: bressed
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
static private Image bressed(final Image image) {
final int i = image.getHeight(null);
final int i340 = image.getWidth(null);
final int[] is = new int[i340 * i];
final PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, i340, i, is, 0, i340);
try {
pixelgrabber.grabPixels();
} catch (final InterruptedException ignored) {
}
final Color color = new Color(247, 255, 165);
for (int i341 = 0; i341 < i340 * i; i341++)
if (is[i341] != is[i340 * i - 1]) {
is[i341] = color.getRGB();
}
return xt.createImage(new MemoryImageSource(i340, i, is, 0, i340));
}
示例4: Sprite
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
public Sprite(String img) {
try {
Image image = Toolkit.getDefaultToolkit().getImage(location + img + ".png");
ImageIcon sprite = new ImageIcon(image);
myWidth = sprite.getIconWidth();
myHeight = sprite.getIconHeight();
anInt1444 = myWidth;
anInt1445 = myHeight;
drawOffsetX = 0;
drawOffsetY = 0;
myPixels = new int[myWidth * myHeight];
PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, myWidth, myHeight, myPixels, 0, myWidth);
pixelgrabber.grabPixels();
image = null;
setTransparency(255, 0, 255);
} catch (Exception _ex) {
System.out.println(_ex);
}
}
示例5: hasAlpha
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
public static boolean hasAlpha( Image image ) {
// If buffered image, the color model is readily available
if ( image instanceof BufferedImage ) {
BufferedImage bimage = (BufferedImage) image;
return bimage.getColorModel().hasAlpha();
}
// Use a pixel grabber to retrieve the image's color model;
// grabbing a single pixel is usually sufficient
PixelGrabber pg = new PixelGrabber( image, 0, 0, 1, 1, false );
try {
pg.grabPixels();
}
catch ( InterruptedException e ) {
}
// Get the image's color model
ColorModel cm = pg.getColorModel();
return cm.hasAlpha();
}
示例6: 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;
}
示例7: hasAlpha
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
/**
* This method returns true if the specified image has transparent pixels
* @param image
* @return
*/
public static boolean hasAlpha(java.awt.Image image) {
// If buffered image, the color model is readily available
if (image instanceof BufferedImage) {
BufferedImage bimage = (BufferedImage)image;
return bimage.getColorModel().hasAlpha();
}
// Use a pixel grabber to retrieve the image's color model;
// grabbing a single pixel is usually sufficient
PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
try {
pg.grabPixels();
} catch (InterruptedException e) {
}
// Get the image's color model
ColorModel cm = pg.getColorModel();
return cm.hasAlpha();
}
示例8: readImage
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
static private void readImage(
final String urlString,
final int w,
final int h,
final int[] data ) throws IOException, InterruptedException
{
final URL url = new URL( urlString );
final BufferedImage jpg = ImageIO.read( url );
/* This gymnastic is necessary to get reproducible gray
* values, just opening a JPG or PNG, even when saved by
* ImageIO, and grabbing its pixels results in gray values
* with a non-matching gamma transfer function, I cannot tell
* why... */
final BufferedImage image =
new BufferedImage( w, h, BufferedImage.TYPE_INT_ARGB );
image.createGraphics().drawImage( jpg, 0, 0, null );
final PixelGrabber pg = new PixelGrabber( image, 0, 0, w, h, data, 0, w );
pg.grabPixels();
}
示例9: getPixels
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
private static int[][] getPixels(Image image) throws IOException {
int w = image.getWidth(null);
int h = image.getHeight(null);
int pix[] = new int[w * h];
PixelGrabber grabber = new PixelGrabber(image, 0, 0, w, h, pix, 0, w);
try {
if (!grabber.grabPixels()) {
throw new IOException("Grabber returned false: " + grabber.status());
}
} catch (InterruptedException e) {
e.printStackTrace();
}
int pixels[][] = new int[w][h];
for (int x = w; x-- > 0; ) {
for (int y = h; y-- > 0; ) {
pixels[x][y] = pix[y * w + x];
}
}
return pixels;
}
示例10: 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;
}
示例11: Sprite
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
public Sprite(byte abyte0[], Component component) {
try {
// Image image =
// Toolkit.getDefaultToolkit().getImage(signlink.findcachedir()+"mopar.jpg");
Image image = Toolkit.getDefaultToolkit().createImage(abyte0);
MediaTracker mediatracker = new MediaTracker(component);
mediatracker.addImage(image, 0);
mediatracker.waitForAll();
width = image.getWidth(component);
height = image.getHeight(component);
maxWidth = width;
maxHeight = height;
offsetX = 0;
offsetY = 0;
pixels = new int[width * height];
PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, width,
height, pixels, 0, width);
pixelgrabber.grabPixels();
} catch (Exception _ex) {
System.out.println("Error converting jpg");
}
}
示例12: Sprite
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
public Sprite(byte imageBuf[], Component component) {
try {
// Image image = Toolkit.getDefaultToolkit().getImage(signlink.findcachedir()+"mopar.jpg");
Image image = Toolkit.getDefaultToolkit().createImage(imageBuf);
MediaTracker mediatracker = new MediaTracker(component);
mediatracker.addImage(image, 0);
mediatracker.waitForAll();
spriteWidth = image.getWidth(component);
spriteHeight = image.getHeight(component);
anInt1444 = spriteWidth;
anInt1445 = spriteHeight;
anInt1442 = 0;
anInt1443 = 0;
spritePixels = new int[spriteWidth * spriteHeight];
PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, spriteWidth, spriteHeight, spritePixels, 0, spriteWidth);
pixelgrabber.grabPixels();
} catch (Exception _ex) {
System.out.println("Error converting jpg");
}
}
示例13: 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);
}
示例14: hasAlpha
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
/**
* http://javaalmanac.com/egs/java.awt.image/HasAlpha.html. This method
* returns true if the specified image has transparent pixels
*
* @param image
* the image to check.
*/
public static boolean hasAlpha(Image image) {
// If buffered image, the color model is readily available
if (image instanceof BufferedImage) {
BufferedImage bimage = (BufferedImage) image;
return bimage.getColorModel().hasAlpha();
}
// Use a pixel grabber to retrieve the image's color model;
// grabbing a single pixel is usually sufficient
PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
try {
pg.grabPixels();
} catch (InterruptedException e) {
}
// Get the image's color model
ColorModel cm = pg.getColorModel();
return cm.hasAlpha();
}
示例15: hasAlpha
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
public static boolean hasAlpha(Image image) {
// If buffered image, the color model is readily available
if (image instanceof BufferedImage) {
BufferedImage bimage = (BufferedImage) image;
return bimage.getColorModel().hasAlpha();
}
// Use a pixel grabber to retrieve the image's color model;
// grabbing a single pixel is usually sufficient
PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
try {
pg.grabPixels();
} catch (InterruptedException e) {
}
// Get the image's color model
ColorModel cm = pg.getColorModel();
return cm.hasAlpha();
}