本文整理汇总了Java中java.awt.image.ColorModel.getRGBdefault方法的典型用法代码示例。如果您正苦于以下问题:Java ColorModel.getRGBdefault方法的具体用法?Java ColorModel.getRGBdefault怎么用?Java ColorModel.getRGBdefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.ColorModel
的用法示例。
在下文中一共展示了ColorModel.getRGBdefault方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.awt.image.ColorModel; //导入方法依赖的package包/类
public static void main(String[] args) {
SimpleColorModel scm1 = new SimpleColorModel(3);
SimpleColorModel scm2 = new SimpleColorModel(3);
SimpleColorModel scm3 = new SimpleColorModel(8);
ColorModel rgbcm = ColorModel.getRGBdefault();
try {
if (scm1.equals(scm2)) {
throw new RuntimeException("Test 1 failed: " +
"scm1 should not equal scm2");
}
if (scm1.equals(scm3)) {
throw new RuntimeException("Test 2 failed: " +
"scm1 should not equal scm3");
}
if (scm1.equals(rgbcm) || rgbcm.equals(scm1)) {
throw new RuntimeException("Test 3 failed: " +
"scm1 should not equal rgbcm");
}
} catch (Exception e) {
throw new RuntimeException("Test failed: " + e);
}
}
示例2: bufferAsJpgString
import java.awt.image.ColorModel; //导入方法依赖的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);
}
示例3: getColorModel
import java.awt.image.ColorModel; //导入方法依赖的package包/类
/**
* Returns the color model associated with this configuration that
* supports the specified transparency.
*/
public ColorModel getColorModel(int transparency) {
switch (transparency) {
case Transparency.OPAQUE:
return getColorModel();
case Transparency.BITMASK:
return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
case Transparency.TRANSLUCENT:
return ColorModel.getRGBdefault();
default:
return null;
}
}
示例4: main
import java.awt.image.ColorModel; //导入方法依赖的package包/类
public static void main(String[] args) throws IIOInvalidTreeException {
// getting the writer for the png format
Iterator iter = ImageIO.getImageWritersByFormatName("png");
ImageWriter writer = (ImageWriter) iter.next();
// creating a color model
ColorModel colorModel = ColorModel.getRGBdefault();
// creating a sample model
SampleModel sampleModel = colorModel.createCompatibleSampleModel(640, 480);
// creating a default metadata object
IIOMetadata metaData = writer.getDefaultImageMetadata(new ImageTypeSpecifier(colorModel, sampleModel), null);
String formatName = metaData.getNativeMetadataFormatName();
// first call
Node metaDataNode = metaData.getAsTree(formatName);
try {
metaData.setFromTree(formatName, metaDataNode);
} catch (Exception ex) {
ex.printStackTrace();
}
// second call (bitdepht is already set to an invalid value)
metaDataNode = metaData.getAsTree(formatName);
metaData.setFromTree(formatName, metaDataNode);
}
示例5: getColorModel
import java.awt.image.ColorModel; //导入方法依赖的package包/类
/**
* Gets the instance of <code>ColorModel</code> used to display
* the component on the output device.
* @return the color model used by this component
* @see java.awt.image.ColorModel
* @see java.awt.peer.ComponentPeer#getColorModel()
* @see Toolkit#getColorModel()
* @since JDK1.0
*/
public ColorModel getColorModel() {
ComponentPeer peer = this.peer;
if ((peer != null) && ! (peer instanceof LightweightPeer)) {
return peer.getColorModel();
} else if (GraphicsEnvironment.isHeadless()) {
return ColorModel.getRGBdefault();
} // else
return getToolkit().getColorModel();
}
示例6: TestSurfaceData
import java.awt.image.ColorModel; //导入方法依赖的package包/类
public TestSurfaceData(int width, int height, double scale) {
super(StateTrackable.State.DYNAMIC, SurfaceType.Custom, ColorModel.getRGBdefault());
this.scale = scale;
gc = new TestGraphicsConfig(scale);
this.width = (int) Math.ceil(scale * width);
this.height = (int) Math.ceil(scale * height);
buffImage = new BufferedImage(this.width, this.height,
BufferedImage.TYPE_INT_RGB);
}
示例7: createBufferedImage
import java.awt.image.ColorModel; //导入方法依赖的package包/类
void createBufferedImage() {
// REMIND: Be careful! Is this called everytime there is a
// startProduction? We only want to call it if it is new or
// there is an error
isDefaultBI = false;
try {
biRaster = cmodel.createCompatibleWritableRaster(width, height);
bimage = createImage(cmodel, biRaster,
cmodel.isAlphaPremultiplied(), null);
} catch (Exception e) {
// Create a default image
cmodel = ColorModel.getRGBdefault();
biRaster = cmodel.createCompatibleWritableRaster(width, height);
bimage = createImage(cmodel, biRaster, false, null);
}
int type = bimage.getType();
if ((cmodel == ColorModel.getRGBdefault()) ||
(type == BufferedImage.TYPE_INT_RGB) ||
(type == BufferedImage.TYPE_INT_ARGB_PRE)) {
isDefaultBI = true;
}
else if (cmodel instanceof DirectColorModel) {
DirectColorModel dcm = (DirectColorModel) cmodel;
if (dcm.getRedMask() == 0xff0000 &&
dcm.getGreenMask() == 0xff00 &&
dcm.getBlueMask() == 0xff) {
isDefaultBI = true;
}
}
}
示例8: RotateFilter
import java.awt.image.ColorModel; //导入方法依赖的package包/类
public RotateFilter(double angle) {
this.angle = angle * (Math.PI / 180);
cos = Math.cos(this.angle);
sin = Math.sin(this.angle);
defaultRGBModel = ColorModel.getRGBdefault();
}
示例9: NullSurfaceData
import java.awt.image.ColorModel; //导入方法依赖的package包/类
private NullSurfaceData() {
super(State.IMMUTABLE, SurfaceType.Any, ColorModel.getRGBdefault());
}
示例10: makeImageRep
import java.awt.image.ColorModel; //导入方法依赖的package包/类
protected ImageRepresentation makeImageRep() {
return new ImageRepresentation(this, ColorModel.getRGBdefault(),
false);
}
示例11: convertToRGB
import java.awt.image.ColorModel; //导入方法依赖的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;
}
示例12: run
import java.awt.image.ColorModel; //导入方法依赖的package包/类
/**
* The runnable method for this class. This will produce an image using
* the current RenderableImage and RenderContext and send it to all the
* ImageConsumer currently registered with this class.
*/
public void run() {
// First get the rendered image
RenderedImage rdrdImage;
if (rc != null) {
rdrdImage = rdblImage.createRendering(rc);
} else {
rdrdImage = rdblImage.createDefaultRendering();
}
// And its ColorModel
ColorModel colorModel = rdrdImage.getColorModel();
Raster raster = rdrdImage.getData();
SampleModel sampleModel = raster.getSampleModel();
DataBuffer dataBuffer = raster.getDataBuffer();
if (colorModel == null) {
colorModel = ColorModel.getRGBdefault();
}
int minX = raster.getMinX();
int minY = raster.getMinY();
int width = raster.getWidth();
int height = raster.getHeight();
Enumeration<ImageConsumer> icList;
ImageConsumer ic;
// Set up the ImageConsumers
icList = ics.elements();
while (icList.hasMoreElements()) {
ic = icList.nextElement();
ic.setDimensions(width,height);
ic.setHints(ImageConsumer.TOPDOWNLEFTRIGHT |
ImageConsumer.COMPLETESCANLINES |
ImageConsumer.SINGLEPASS |
ImageConsumer.SINGLEFRAME);
}
// Get RGB pixels from the raster scanline by scanline and
// send to consumers.
int pix[] = new int[width];
int i,j;
int numBands = sampleModel.getNumBands();
int tmpPixel[] = new int[numBands];
for (j = 0; j < height; j++) {
for(i = 0; i < width; i++) {
sampleModel.getPixel(i, j, tmpPixel, dataBuffer);
pix[i] = colorModel.getDataElement(tmpPixel, 0);
}
// Now send the scanline to the Consumers
icList = ics.elements();
while (icList.hasMoreElements()) {
ic = icList.nextElement();
ic.setPixels(0, j, width, 1, colorModel, pix, 0, width);
}
}
// Now tell the consumers we're done.
icList = ics.elements();
while (icList.hasMoreElements()) {
ic = icList.nextElement();
ic.imageComplete(ImageConsumer.STATICIMAGEDONE);
}
}
示例13: PixelGrabber
import java.awt.image.ColorModel; //导入方法依赖的package包/类
/**
* Create a PixelGrabber object to grab the (x, y, w, h) rectangular
* section of pixels from the image produced by the specified
* ImageProducer into the given array.
* The pixels are stored into the array in the default RGB ColorModel.
* The RGB data for pixel (i, j) where (i, j) is inside the rectangle
* (x, y, w, h) is stored in the array at
* {@code pix[(j - y) * scansize + (i - x) + off]}.
* @param ip the {@code ImageProducer} that produces the
* image from which to retrieve pixels
* @param x the x coordinate of the upper left corner of the rectangle
* of pixels to retrieve from the image, relative to the default
* (unscaled) size of the image
* @param y the y coordinate of the upper left corner of the rectangle
* of pixels to retrieve from the image
* @param w the width of the rectangle of pixels to retrieve
* @param h the height of the rectangle of pixels to retrieve
* @param pix the array of integers which are to be used to hold the
* RGB pixels retrieved from the image
* @param off the offset into the array of where to store the first pixel
* @param scansize the distance from one row of pixels to the next in
* the array
* @see ColorModel#getRGBdefault
*/
public PixelGrabber(ImageProducer ip, int x, int y, int w, int h,
int[] pix, int off, int scansize) {
producer = ip;
dstX = x;
dstY = y;
dstW = w;
dstH = h;
dstOff = off;
dstScan = scansize;
intPixels = pix;
imageModel = ColorModel.getRGBdefault();
}