本文整理匯總了Java中java.awt.image.Raster.createPackedRaster方法的典型用法代碼示例。如果您正苦於以下問題:Java Raster.createPackedRaster方法的具體用法?Java Raster.createPackedRaster怎麽用?Java Raster.createPackedRaster使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.image.Raster
的用法示例。
在下文中一共展示了Raster.createPackedRaster方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: bufferAsJpgString
import java.awt.image.Raster; //導入方法依賴的package包/類
/**
* Converts raw data into JPG image and encode it into Base64 string for sending it to the JS client
*
* @param rawImg
* raw image bytes
* @return Base64 encoded string with JPG image
*/
private String bufferAsJpgString(byte[] rawImg) {
int[] pixels = new int[rawImg.length];
for (int i = 0; i < rawImg.length; i++) {
pixels[i] = (int) rawImg[i];
}
DataBufferInt buffer = new DataBufferInt(pixels, pixels.length);
WritableRaster raster = Raster.createPackedRaster(buffer, IMG_SIZE, IMG_SIZE, IMG_SIZE, BAND_MASKS, null);
ColorModel cm = ColorModel.getRGBdefault();
BufferedImage image = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);
byte[] imgBytes = null;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
ImageIO.write(image, "JPG", baos);
baos.flush();
imgBytes = baos.toByteArray();
} catch (IOException e) {
// TODO log exception
}
byte[] encoded = Base64.getEncoder().encode(imgBytes);
return new String(encoded);
}
示例2: getOpaqueRGBImage
import java.awt.image.Raster; //導入方法依賴的package包/類
public BufferedImage getOpaqueRGBImage() {
if (bimage.getType() == BufferedImage.TYPE_INT_ARGB) {
int w = bimage.getWidth();
int h = bimage.getHeight();
int size = w * h;
// Note that we steal the data array here, but only for reading...
DataBufferInt db = (DataBufferInt)biRaster.getDataBuffer();
int[] pixels = SunWritableRaster.stealData(db, 0);
for (int i = 0; i < size; i++) {
if ((pixels[i] >>> 24) != 0xff) {
return bimage;
}
}
ColorModel opModel = new DirectColorModel(24,
0x00ff0000,
0x0000ff00,
0x000000ff);
int bandmasks[] = {0x00ff0000, 0x0000ff00, 0x000000ff};
WritableRaster opRaster = Raster.createPackedRaster(db, w, h, w,
bandmasks,
null);
try {
BufferedImage opImage = createImage(opModel, opRaster,
false, null);
return opImage;
} catch (Exception e) {
return bimage;
}
}
return bimage;
}
示例3: platformImageBytesToImage
import java.awt.image.Raster; //導入方法依賴的package包/類
/**
* Translates either a byte array or an input stream which contain
* platform-specific image data in the given format into an Image.
*/
@Override
protected Image platformImageBytesToImage(byte[] bytes, long format)
throws IOException {
String mimeType = null;
if (format == CF_PNG) {
mimeType = "image/png";
} else if (format == CF_JFIF) {
mimeType = "image/jpeg";
}
if (mimeType != null) {
return standardImageBytesToImage(bytes, mimeType);
}
int[] imageData = platformImageBytesToImageData(bytes, format);
if (imageData == null) {
throw new IOException("data translation failed");
}
int len = imageData.length - 2;
int width = imageData[len];
int height = imageData[len + 1];
DataBufferInt buffer = new DataBufferInt(imageData, len);
WritableRaster raster = Raster.createPackedRaster(buffer, width,
height, width,
bandmasks, null);
return new BufferedImage(directColorModel, raster, false, null);
}
示例4: testIntRaster
import java.awt.image.Raster; //導入方法依賴的package包/類
private static void testIntRaster() {
WritableRaster srcRaster, dstRaster;
int[] pixels =
{ 11, 12, 13, 14,
21, 22, 23, 24,
31, 32, 33, 34,
41, 42, 43, 44 };
DataBuffer db = new DataBufferInt(pixels, pixels.length);
srcRaster =
Raster.createPackedRaster(db, 4, 4, 4, offsets, null);
srcRaster = srcRaster.createWritableChild(1, 1, 3, 3, 0, 0, null);
dstRaster = rop.filter(srcRaster, null);
}
示例5: convertToRGB
import java.awt.image.Raster; //導入方法依賴的package包/類
private void convertToRGB() {
int w = bimage.getWidth();
int h = bimage.getHeight();
int size = w*h;
DataBufferInt dbi = new DataBufferInt(size);
// Note that stealData() requires a markDirty() afterwards
// since we modify the data in it.
int newpixels[] = SunWritableRaster.stealData(dbi, 0);
if (cmodel instanceof IndexColorModel &&
biRaster instanceof ByteComponentRaster &&
biRaster.getNumDataElements() == 1)
{
ByteComponentRaster bct = (ByteComponentRaster) biRaster;
byte[] data = bct.getDataStorage();
int coff = bct.getDataOffset(0);
for (int i=0; i < size; i++) {
newpixels[i] = srcLUT[data[coff+i]&0xff];
}
}
else {
Object srcpixels = null;
int off=0;
for (int y=0; y < h; y++) {
for (int x=0; x < w; x++) {
srcpixels=biRaster.getDataElements(x, y, srcpixels);
newpixels[off++] = cmodel.getRGB(srcpixels);
}
}
}
// We modified the data array directly above so mark it as dirty now...
SunWritableRaster.markDirty(dbi);
isSameCM = false;
cmodel = ColorModel.getRGBdefault();
int bandMasks[] = {0x00ff0000,
0x0000ff00,
0x000000ff,
0xff000000};
biRaster = Raster.createPackedRaster(dbi,w,h,w,
bandMasks,null);
bimage = createImage(cmodel, biRaster,
cmodel.isAlphaPremultiplied(), null);
srcLUT = null;
isDefaultBI = true;
}