本文整理汇总了Java中java.awt.image.WritableRaster.setPixels方法的典型用法代码示例。如果您正苦于以下问题:Java WritableRaster.setPixels方法的具体用法?Java WritableRaster.setPixels怎么用?Java WritableRaster.setPixels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.WritableRaster
的用法示例。
在下文中一共展示了WritableRaster.setPixels方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toImage
import java.awt.image.WritableRaster; //导入方法依赖的package包/类
/**
* Convert {@link AbstractImage} to {@link Image}.
*
* @param in
* the input image
* @return the converted image
*/
public static Image toImage(AbstractImage in) {
if (in == null) {
return null;
}
BufferedImage res = new BufferedImage(in.width, in.height, BufferedImage.TYPE_INT_ARGB);
int[] pixels = new int[in.pixels.length];
for (int i = 0; i < pixels.length; i += 1) {
pixels[i] = in.pixels[i] & 0xFF;
}
WritableRaster raster = Raster.createWritableRaster(res.getSampleModel(), null);
raster.setPixels(0, 0, in.width, in.height, pixels);
res.setData(raster);
res.flush();
return res;
}
示例2: createImage
import java.awt.image.WritableRaster; //导入方法依赖的package包/类
/**
*
* @param gir
* @param x
* @param y
* @param width
* @param height
* @param zoom
* @return
*/
private BufferedImage createImage(GeoImageReader gir, int x, int y, int width, int height, float zoom) {
BufferedImage bufferedImage = new BufferedImage(width, height, gir.getType(true));
int[] nat;
WritableRaster raster = bufferedImage.getRaster();
// Put the pixels on the raster.
nat = gir.readAndDecimateTile(x, y,
(int) (width * zoom),
(int) (height * zoom),
width, height,((SarImageReader)gir).getWidth(),
((SarImageReader)gir).getHeight() ,true,activeBand);
raster.setPixels(0, 0, width, height, nat);
return bufferedImage;
}
示例3: thresholdImage
import java.awt.image.WritableRaster; //导入方法依赖的package包/类
public BufferedImage thresholdImage(BufferedImage image, int threshold) {
BufferedImage result = new BufferedImage(image.getWidth(),
image.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
result.getGraphics().drawImage(image, 0, 0, null);
WritableRaster raster = result.getRaster();
int[] pixels = new int[image.getWidth()];
for (int y = 0; y < image.getHeight(); y++) {
raster.getPixels(0, y, image.getWidth(), 1, pixels);
for (int i = 0; i < pixels.length; i++) {
if (pixels[i] < threshold) {
pixels[i] = 0;
} else {
pixels[i] = 255;
}
}
raster.setPixels(0, y, image.getWidth(), 1, pixels);
}
return result;
}
示例4: createImage
import java.awt.image.WritableRaster; //导入方法依赖的package包/类
public static BufferedImage createImage(int[]tile, int width, int height, GeoImageReader gimage) {
BufferedImage bufferedImage = new BufferedImage(width, height, gimage.getType(true));
WritableRaster raster = bufferedImage.getRaster();
// Put the pixels on the raster.
if(tile!=null){
raster.setPixels(0, 0, width, height, tile);
}
return bufferedImage;
}
示例5: getImageFromArray
import java.awt.image.WritableRaster; //导入方法依赖的package包/类
public static Image getImageFromArray(int[] pixels, int width, int height) {
BufferedImage image = new BufferedImage(width, height+1, BufferedImage.TYPE_INT_ARGB);
WritableRaster raster = (WritableRaster) image.getData();
System.out.println("px;" + pixels.length + " as opposed to " + (height*width));
raster.setPixels(0,0,width,height-1,pixels);
return image;
}
示例6: createImage
import java.awt.image.WritableRaster; //导入方法依赖的package包/类
private BufferedImage createImage(GeoImageReader gir, int x, int y, int width, int height) {
BufferedImage bufferedImage = new BufferedImage(width, height, gir.getType(true));
//System.out.println(zoom);
WritableRaster raster = bufferedImage.getRaster();
// Put the pixels on the raster.
//if (bands.length == 1) {
// int band = band;
nat = gir.readTile(x, y, width, height,band);
raster.setPixels(0, 0, width, height, nat);
/* } else {
int b = 0;
for (int band : bands) {
gir.setBand(band);
nat = gir.readTile(x, y, width, height);
///if (zoom == 1) {
raster.setSamples(0, 0, width, height, b, nat);
/*
* for (int h = 0; h < height; h++) {
* int temp = h * width;
* for (int w = 0; w < width; w++) {
* raster.setSample(w, h, b, nat[temp + w]);
* }
* }
**/
/*
* } else {
* for (int h = 0; h < height; h++) {
* int temp = (int) (h * zoom) * (int) (width * zoom);
* for (int w = 0; w < width; w++) {
* try {
* raster.setSample(w, h, b, nat[temp + (int) (w * zoom)]);
* } catch (Exception e) {
* }
* }
* }
* }
**/
/* b++;
if (b > raster.getNumBands()) {
break;
}
}
}*/
return bufferedImage;
}
示例7: grabPixels
import java.awt.image.WritableRaster; //导入方法依赖的package包/类
/**
* Put the scanline y of the source ROI view Raster into the
* 1-line Raster for writing. This handles ROI and band
* rearrangements, and expands indexed images. Subsampling is
* done in the native code.
* This is called by the native code.
*/
private void grabPixels(int y) {
Raster sourceLine = null;
if (indexed) {
sourceLine = srcRas.createChild(sourceXOffset,
sourceYOffset+y,
sourceWidth, 1,
0, 0,
new int [] {0});
// If the image has BITMASK transparency, we need to make sure
// it gets converted to 32-bit ARGB, because the JPEG encoder
// relies upon the full 8-bit alpha channel.
boolean forceARGB =
(indexCM.getTransparency() != Transparency.OPAQUE);
BufferedImage temp = indexCM.convertToIntDiscrete(sourceLine,
forceARGB);
sourceLine = temp.getRaster();
} else {
sourceLine = srcRas.createChild(sourceXOffset,
sourceYOffset+y,
sourceWidth, 1,
0, 0,
srcBands);
}
if (convertTosRGB) {
if (debug) {
System.out.println("Converting to sRGB");
}
// The first time through, converted is null, so
// a new raster is allocated. It is then reused
// on subsequent lines.
converted = convertOp.filter(sourceLine, converted);
sourceLine = converted;
}
if (isAlphaPremultiplied) {
WritableRaster wr = sourceLine.createCompatibleWritableRaster();
int[] data = null;
data = sourceLine.getPixels(sourceLine.getMinX(), sourceLine.getMinY(),
sourceLine.getWidth(), sourceLine.getHeight(),
data);
wr.setPixels(sourceLine.getMinX(), sourceLine.getMinY(),
sourceLine.getWidth(), sourceLine.getHeight(),
data);
srcCM.coerceData(wr, false);
sourceLine = wr.createChild(wr.getMinX(), wr.getMinY(),
wr.getWidth(), wr.getHeight(),
0, 0,
srcBands);
}
raster.setRect(sourceLine);
if ((y > 7) && (y%8 == 0)) { // Every 8 scanlines
cbLock.lock();
try {
processImageProgress((float) y / (float) sourceHeight * 100.0F);
} finally {
cbLock.unlock();
}
}
}