本文整理汇总了Java中java.awt.image.PixelGrabber.getPixels方法的典型用法代码示例。如果您正苦于以下问题:Java PixelGrabber.getPixels方法的具体用法?Java PixelGrabber.getPixels怎么用?Java PixelGrabber.getPixels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.PixelGrabber
的用法示例。
在下文中一共展示了PixelGrabber.getPixels方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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.");
}
}
}
示例3: 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);
}
示例4: writeObject
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
/**
* Code derived from
* http://www.dcs.shef.ac.uk/~tom/Java/Power/image_serialization.html
*/
private void writeObject(ObjectOutputStream objectstream)
throws IOException {
// write non-transient, non-static data
objectstream.defaultWriteObject();
PixelGrabber grabber = new PixelGrabber(bitmap, 0, 0, -1, -1, true);
if (colorModel == COLORMODEL_IMAGEICON && bitmap != null) {
try {
grabber.grabPixels();
} catch (InterruptedException e) {
System.out.println("error grabbing pixels");
}
Object pix = grabber.getPixels();
Dimension dim = new Dimension(bitmap.getWidth(this), bitmap.getHeight(this));
objectstream.writeObject(dim);
objectstream.writeObject(pix);
}
}
示例5: transparencyBlackColor
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
/**
* 将黑色颜色部分透明化
*
* @param img
* @return
*/
final static public Image transparencyBlackColor(final Image img) {
int width = img.getWidth(null);
int height = img.getHeight(null);
PixelGrabber pg = new PixelGrabber(img, 0, 0, width, height, true);
try {
pg.grabPixels();
} catch (InterruptedException e) {
e.printStackTrace();
}
int pixels[] = (int[]) pg.getPixels();
int length = pixels.length;
for (int i = 0; i < length; i++) {
if (pixels[i] == 0) {
pixels[i] = 0xffffff;
}
}
return toolKit.createImage(new MemoryImageSource(width, height, pixels, 0, width));
}
示例6: hashImage
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
/**
* 生成Image的hash序列
*
* @param img
* @return
*/
public static int hashImage(Image img) {
int hash_result = 0;
int width = img.getWidth(null);
int height = img.getHeight(null);
hash_result = (hash_result << 7) ^ height;
hash_result = (hash_result << 7) ^ width;
PixelGrabber pg = new PixelGrabber(img, 0, 0, width, height, true);
try {
pg.grabPixels();
} catch (InterruptedException e) {
e.printStackTrace();
}
int pixels[] = (int[]) pg.getPixels();
for (int pixel = 0; pixel < 20; ++pixel) {
int x = (pixel * 50) % width;
int y = (pixel * 100) % height;
hash_result = (hash_result << 7) ^ pixels[x + width * y];
}
return hash_result;
}
示例7: 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;
}
示例8: 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];
}
示例9: grabPixels
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
static int[] grabPixels(Object imageobj, int width, int height,
int[] pixels, int startRow, int nRows) {
java.awt.Image image = (java.awt.Image) imageobj;
PixelGrabber pixelGrabber = (pixels == null ? new PixelGrabber(image, 0,
0, width, height, true) : new PixelGrabber(image, 0, startRow, width, nRows, pixels, 0,
width));
try {
pixelGrabber.grabPixels();
} catch (InterruptedException e) {
return null;
}
return (int[]) pixelGrabber.getPixels();
}
示例10: getImageIntPixels
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
public static int[] getImageIntPixels(Image image, int x, int y, int width, int height, boolean allowDeoptimizingDirectRead)
{
if (image instanceof BufferedImage)
{
BufferedImage bim = (BufferedImage) image;
WritableRaster raster = bim.getRaster();
if (allowDeoptimizingDirectRead && raster.getParent() == null
&& raster.getDataBuffer().getNumBanks() == 1)
{
DataBuffer b = bim.getRaster().getDataBuffer();
if (b instanceof DataBufferInt)
{
int[] array = ((DataBufferInt) b).getData();
return array;
}
}
return bim.getRGB(x, y, width, height, null, 0, width);
}
PixelGrabber grabber = new PixelGrabber(image, x, y, width, height,
true);
try
{
grabber.grabPixels();
return (int[]) grabber.getPixels();
} catch (InterruptedException ex)
{
throw new RuntimeException("Pixel read operation was interrupted",
ex);
}
}
示例11: 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;
}
示例12: 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;
}
示例13: getRMXPDialog
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
public final static Image getRMXPDialog(String fileName, int width, int height) {
if (lazyImages == null) {
lazyImages = new HashMap<String, Image>(10);
}
Image dialog = GraphicsUtils.loadImage(fileName);
int w = dialog.getWidth(null);
int h = dialog.getHeight(null);
PixelGrabber pg = new PixelGrabber(dialog, 0, 0, w, h, true);
try {
pg.grabPixels();
} catch (InterruptedException e) {
}
int[] pixels = (int[]) pg.getPixels();
int index = -1;
int count = 0;
int pixel;
for (int i = 0; i < 5; i++) {
pixel = pixels[(141 + i) + w * 12];
if (index == -1) {
index = pixel;
}
if (index == pixel) {
count++;
}
}
if (count == 5) {
return getRMXPDialog(dialog, width, height, 16, 5);
} else if (count == 1) {
return getRMXPDialog(dialog, width, height, 27, 5);
} else if (count == 2) {
return getRMXPDialog(dialog, width, height, 20, 5);
} else {
return getRMXPDialog(dialog, width, height, 27, 5);
}
}
示例14: getImageData
import java.awt.image.PixelGrabber; //导入方法依赖的package包/类
private int[] getImageData(Image img) {
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();
return data;
}
示例15: 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( );
}