本文整理汇总了Java中java.awt.image.BufferedImage.getColorModel方法的典型用法代码示例。如果您正苦于以下问题:Java BufferedImage.getColorModel方法的具体用法?Java BufferedImage.getColorModel怎么用?Java BufferedImage.getColorModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.BufferedImage
的用法示例。
在下文中一共展示了BufferedImage.getColorModel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDataBP
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static SurfaceData createDataBP(BufferedImage bImg,
SurfaceType sType) {
BytePackedRaster bpRaster =
(BytePackedRaster)bImg.getRaster();
BufImgSurfaceData bisd =
new BufImgSurfaceData(bpRaster.getDataBuffer(), bImg, sType);
ColorModel cm = bImg.getColorModel();
IndexColorModel icm = ((cm instanceof IndexColorModel)
? (IndexColorModel) cm
: null);
bisd.initRaster(bpRaster.getDataStorage(),
bpRaster.getDataBitOffset() / 8,
bpRaster.getDataBitOffset() & 7,
bpRaster.getWidth(),
bpRaster.getHeight(),
0,
bpRaster.getScanlineStride(),
icm);
return bisd;
}
示例2: getDefaultPalette
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private static synchronized byte[] getDefaultPalette() {
if (defaultPalette == null) {
BufferedImage img = new BufferedImage(1, 1,
BufferedImage.TYPE_BYTE_INDEXED);
IndexColorModel icm = (IndexColorModel) img.getColorModel();
final int size = icm.getMapSize();
byte[] r = new byte[size];
byte[] g = new byte[size];
byte[] b = new byte[size];
icm.getReds(r);
icm.getGreens(g);
icm.getBlues(b);
defaultPalette = new byte[size * 3];
for (int i = 0; i < size; i++) {
defaultPalette[3 * i + 0] = r[i];
defaultPalette[3 * i + 1] = g[i];
defaultPalette[3 * i + 2] = b[i];
}
}
return defaultPalette;
}
示例3: copyImage
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
* we don't want to alter original image (actually converted image)
* since we need this each time for reference
* @param coverImage original carrier/cover image
* @return a copy of supplied image
*/
public BufferedImage copyImage(BufferedImage coverImage) {
ColorModel colorModel = coverImage.getColorModel();
boolean isAlphaPremultiplied = coverImage.isAlphaPremultiplied();
WritableRaster raster = coverImage.copyData(null);
BufferedImage newImage = new BufferedImage(colorModel, raster,
isAlphaPremultiplied, null);
return newImage;
}
示例4: JFIFExtensionMarkerSegment
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
JFIFExtensionMarkerSegment(BufferedImage thumbnail)
throws IllegalThumbException {
super(JPEG.APP0);
ColorModel cm = thumbnail.getColorModel();
int csType = cm.getColorSpace().getType();
if (cm.hasAlpha()) {
throw new IllegalThumbException();
}
if (cm instanceof IndexColorModel) {
code = THUMB_PALETTE;
thumb = new JFIFThumbPalette(thumbnail);
} else if (csType == ColorSpace.TYPE_RGB) {
code = THUMB_RGB;
thumb = new JFIFThumbRGB(thumbnail);
} else if (csType == ColorSpace.TYPE_GRAY) {
code = THUMB_JPEG;
thumb = new JFIFThumbJPEG(thumbnail);
} else {
throw new IllegalThumbException();
}
}
示例5: createDataBC
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static SurfaceData createDataBC(BufferedImage bImg,
SurfaceType sType,
int primaryBank,
double scaleX, double scaleY)
{
ByteComponentRaster bcRaster =
(ByteComponentRaster)bImg.getRaster();
BufImgSurfaceData bisd =
new BufImgSurfaceData(bcRaster.getDataBuffer(), bImg, sType,
scaleX, scaleY);
ColorModel cm = bImg.getColorModel();
IndexColorModel icm = ((cm instanceof IndexColorModel)
? (IndexColorModel) cm
: null);
bisd.initRaster(bcRaster.getDataStorage(),
bcRaster.getDataOffset(primaryBank), 0,
bcRaster.getWidth(),
bcRaster.getHeight(),
bcRaster.getPixelStride(),
bcRaster.getScanlineStride(),
icm);
return bisd;
}
示例6: createDataBC
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static SurfaceData createDataBC(BufferedImage bImg,
SurfaceType sType,
int primaryBank) {
ByteComponentRaster bcRaster =
(ByteComponentRaster)bImg.getRaster();
BufImgSurfaceData bisd =
new BufImgSurfaceData(bcRaster.getDataBuffer(), bImg, sType);
ColorModel cm = bImg.getColorModel();
IndexColorModel icm = ((cm instanceof IndexColorModel)
? (IndexColorModel) cm
: null);
bisd.initRaster(bcRaster.getDataStorage(),
bcRaster.getDataOffset(primaryBank), 0,
bcRaster.getWidth(),
bcRaster.getHeight(),
bcRaster.getPixelStride(),
bcRaster.getScanlineStride(),
icm);
return bisd;
}
示例7: BufferedImageGraphicsConfig
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public BufferedImageGraphicsConfig(BufferedImage bufImg, Component comp) {
if (comp == null) {
this.gd = new BufferedImageDevice(this);
} else {
Graphics2D g2d = (Graphics2D)comp.getGraphics();
this.gd = g2d.getDeviceConfiguration().getDevice();
}
this.model = bufImg.getColorModel();
this.raster = bufImg.getRaster().createCompatibleWritableRaster(1, 1);
this.width = bufImg.getWidth();
this.height = bufImg.getHeight();
}
示例8: isRescaleOpValid
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**************************** RescaleOp support *****************************/
public static boolean isRescaleOpValid(RescaleOp rop,
BufferedImage srcImg)
{
int numFactors = rop.getNumFactors();
ColorModel srcCM = srcImg.getColorModel();
if (srcCM instanceof IndexColorModel) {
throw new
IllegalArgumentException("Rescaling cannot be "+
"performed on an indexed image");
}
if (numFactors != 1 &&
numFactors != srcCM.getNumColorComponents() &&
numFactors != srcCM.getNumComponents())
{
throw new IllegalArgumentException("Number of scaling constants "+
"does not equal the number of"+
" of color or color/alpha "+
" components");
}
int csType = srcCM.getColorSpace().getType();
if (csType != ColorSpace.TYPE_RGB &&
csType != ColorSpace.TYPE_GRAY)
{
// Not prepared to deal with other color spaces
return false;
}
if (numFactors == 2 || numFactors > 4) {
// Not really prepared to handle this at the native level, so...
return false;
}
return true;
}
示例9: compare
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private boolean compare(final BufferedImage in, final BufferedImage out) {
final int width = in.getWidth();
int height = in.getHeight();
if (out.getWidth() != width || out.getHeight() != height) {
throw new RuntimeException("Dimensions changed!");
}
Raster oldras = in.getRaster();
ColorModel oldcm = in.getColorModel();
Raster newras = out.getRaster();
ColorModel newcm = out.getColorModel();
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
Object oldpixel = oldras.getDataElements(i, j, null);
int oldrgb = oldcm.getRGB(oldpixel);
int oldalpha = oldcm.getAlpha(oldpixel);
Object newpixel = newras.getDataElements(i, j, null);
int newrgb = newcm.getRGB(newpixel);
int newalpha = newcm.getAlpha(newpixel);
if (newrgb != oldrgb ||
newalpha != oldalpha) {
// showDiff(in, out);
throw new RuntimeException("Pixels differ at " + i +
", " + j + " new = " + Integer.toHexString(newrgb) + " old = " + Integer.toHexString(oldrgb));
}
}
}
return true;
}
示例10: getContext
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static PaintContext getContext(BufferedImage bufImg,
AffineTransform xform,
RenderingHints hints,
Rectangle devBounds) {
WritableRaster raster = bufImg.getRaster();
ColorModel cm = bufImg.getColorModel();
int maxw = devBounds.width;
Object val = hints.get(RenderingHints.KEY_INTERPOLATION);
boolean filter =
(val == null
? (hints.get(RenderingHints.KEY_RENDERING) == RenderingHints.VALUE_RENDER_QUALITY)
: (val != RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR));
if (raster instanceof IntegerInterleavedRaster &&
(!filter || isFilterableDCM(cm)))
{
IntegerInterleavedRaster iir = (IntegerInterleavedRaster) raster;
if (iir.getNumDataElements() == 1 && iir.getPixelStride() == 1) {
return new Int(iir, cm, xform, maxw, filter);
}
} else if (raster instanceof ByteInterleavedRaster) {
ByteInterleavedRaster bir = (ByteInterleavedRaster) raster;
if (bir.getNumDataElements() == 1 && bir.getPixelStride() == 1) {
if (filter) {
if (isFilterableICM(cm)) {
return new ByteFilter(bir, cm, xform, maxw);
}
} else {
return new Byte(bir, cm, xform, maxw);
}
}
}
return new Any(raster, cm, xform, maxw, filter);
}
示例11: printImageInfo
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private void printImageInfo(BufferedImage image) {
System.out.println("Image Type: " + image.getType());
ColorModel colorModel = image.getColorModel();
pixelSize = colorModel.getPixelSize();
System.out.println("Pixel size: " + pixelSize);
System.out.println("Alpha channel present: "
+ colorModel.hasAlpha());
}
示例12: changeColourMap
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public BufferedImage changeColourMap(BufferedImage userSpaceImage,
IndexColorModel customIndexColorModel) {
ColorModel originalCM = userSpaceImage.getColorModel();
if (originalCM instanceof IndexColorModel) {
boolean isAlphaPremultiplied = userSpaceImage.isAlphaPremultiplied();
WritableRaster raster = userSpaceImage.copyData(null);
BufferedImage newImage = new BufferedImage(customIndexColorModel,
raster, isAlphaPremultiplied, null);
return newImage;
} else {
return null;
}
}
示例13: BufImgSurfaceData
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public BufImgSurfaceData(DataBuffer db,
BufferedImage bufImg,
SurfaceType sType,
double scaleX,
double scaleY)
{
super(SunWritableRaster.stealTrackable(db),
sType, bufImg.getColorModel());
this.bufImg = bufImg;
this.scaleX = scaleX;
this.scaleY = scaleY;
}
示例14: setImage
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public void setImage(BufferedImage image) {
if(decompressor != null) {
ColorModel cm = image.getColorModel();
tmpImage =
new BufferedImage(cm,
image.getRaster().createCompatibleWritableRaster(1, 1),
cm.isAlphaPremultiplied(),
null);
decompressor.setImage(tmpImage);
}
super.setImage(image);
}
示例15: cropImage
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private BufferedImage cropImage(BufferedImage bi, char c)
{
ColorModel cm = bi.getColorModel();
int startX = 0;
int endX = fontMetrics.charWidth(c);
// coming from the right, going to the left
for (int x = fontMetrics.charWidth(c); x < bi.getWidth(); x++)
{
boolean hasAlpha = false;
for (int y = 0; y < bi.getHeight(); y++)
{
if (cm.getAlpha(bi.getRGB(x, y)) != 0)
{
hasAlpha = true;
endX = x+1;
break;
}
}
if(!hasAlpha) break;
}
//System.out.println(c+" StartX: "+startX+", endX: "+endX);
/*
if(c == ' ')
{
endX = fontMetrics.charWidth(' ');
startX = 0;
}
*/
//endX++;
//endX++;
// large fonts need extra space
//while(endX - startX < fontMetrics.charWidth(c)) endX++;
BufferedImage cropped = new BufferedImage(endX - startX, fontMetrics.getMaxAscent()+fontMetrics.getMaxDescent(),
bi.getType());
cropped.getGraphics().drawImage(bi, -startX, 0, null);
return cropped;
}