下面列出了java.awt.image.IndexColorModel#getPixelSize() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Returns an index color model with specified opacity (alpha).
* @param icm an index color model from which to copy RGBs.
* @param alpha opacity in the range [0.0,1.0].
* @return the index color model with alpha.
*/
public static IndexColorModel setAlpha(IndexColorModel icm, double alpha) {
int bits = icm.getPixelSize();
int size = icm.getMapSize();
byte[] r = new byte[size];
byte[] g = new byte[size];
byte[] b = new byte[size];
byte[] a = new byte[size];
icm.getReds(r);
icm.getGreens(g);
icm.getBlues(b);
byte ia = (byte)(255.0*alpha+0.5);
for (int i=0; i<size; ++i)
a[i] = ia;
return new IndexColorModel(bits,size,r,g,b,a);
}
/**
* Returns an index color model with specified opacities (alphas).
* @param icm an index color model from which to copy RGBs.
* @param alpha array of opacities in the range [0.0,1.0].
* @return the index color model with alphas.
*/
public static IndexColorModel setAlpha(IndexColorModel icm, float[] alpha) {
int bits = icm.getPixelSize();
int size = icm.getMapSize();
byte[] r = new byte[size];
byte[] g = new byte[size];
byte[] b = new byte[size];
byte[] a = new byte[size];
icm.getReds(r);
icm.getGreens(g);
icm.getBlues(b);
int n = min(size,alpha.length);
for (int i=0; i<n; ++i)
a[i] = (byte)(255.0f*alpha[i]+0.5f);
return new IndexColorModel(bits,size,r,g,b,a);
}
public static void main(String args[]) {
IndexColorModel cm =
new IndexColorModel(8, 1, new byte[]{(byte) 128}, new byte[]{(byte) 128}, new byte[]{(byte) 128});
cm.getTransparency();
cm.getComponentSize();
cm.isAlphaPremultiplied();
cm.hasAlpha();
cm.isAlphaPremultiplied();
cm.getTransferType();
cm.getPixelSize();
cm.getComponentSize();
cm.getNumComponents();
cm.getNumColorComponents();
cm.getRed(20);
cm.getGreen(20);
cm.getBlue(20);
cm.getAlpha(20);
cm.getRGB(20);
cm.isAlphaPremultiplied();
}
protected void drawDIBImage(byte[] image,
float destX, float destY,
float destWidth, float destHeight,
float srcX, float srcY,
float srcWidth, float srcHeight,
int sampleBitsPerPixel,
IndexColorModel icm) {
int bitCount = 24;
byte[] bmiColors = null;
if (icm != null) {
bitCount = sampleBitsPerPixel;
bmiColors = new byte[(1<<icm.getPixelSize())*4];
for (int i=0;i<icm.getMapSize(); i++) {
bmiColors[i*4+0]=(byte)(icm.getBlue(i)&0xff);
bmiColors[i*4+1]=(byte)(icm.getGreen(i)&0xff);
bmiColors[i*4+2]=(byte)(icm.getRed(i)&0xff);
}
}
drawDIBImage(getPrintDC(), image,
destX, destY,
destWidth, destHeight,
srcX, srcY,
srcWidth, srcHeight,
bitCount, bmiColors);
}
protected void drawDIBImage(byte[] image,
float destX, float destY,
float destWidth, float destHeight,
float srcX, float srcY,
float srcWidth, float srcHeight,
int sampleBitsPerPixel,
IndexColorModel icm) {
int bitCount = 24;
byte[] bmiColors = null;
if (icm != null) {
bitCount = sampleBitsPerPixel;
bmiColors = new byte[(1<<icm.getPixelSize())*4];
for (int i=0;i<icm.getMapSize(); i++) {
bmiColors[i*4+0]=(byte)(icm.getBlue(i)&0xff);
bmiColors[i*4+1]=(byte)(icm.getGreen(i)&0xff);
bmiColors[i*4+2]=(byte)(icm.getRed(i)&0xff);
}
}
drawDIBImage(getPrintDC(), image,
destX, destY,
destWidth, destHeight,
srcX, srcY,
srcWidth, srcHeight,
bitCount, bmiColors);
}
protected void drawDIBImage(byte[] image,
float destX, float destY,
float destWidth, float destHeight,
float srcX, float srcY,
float srcWidth, float srcHeight,
int sampleBitsPerPixel,
IndexColorModel icm) {
int bitCount = 24;
byte[] bmiColors = null;
if (icm != null) {
bitCount = sampleBitsPerPixel;
bmiColors = new byte[(1<<icm.getPixelSize())*4];
for (int i=0;i<icm.getMapSize(); i++) {
bmiColors[i*4+0]=(byte)(icm.getBlue(i)&0xff);
bmiColors[i*4+1]=(byte)(icm.getGreen(i)&0xff);
bmiColors[i*4+2]=(byte)(icm.getRed(i)&0xff);
}
}
drawDIBImage(getPrintDC(), image,
destX, destY,
destWidth, destHeight,
srcX, srcY,
srcWidth, srcHeight,
bitCount, bmiColors);
}
protected void drawDIBImage(byte[] image,
float destX, float destY,
float destWidth, float destHeight,
float srcX, float srcY,
float srcWidth, float srcHeight,
int sampleBitsPerPixel,
IndexColorModel icm) {
int bitCount = 24;
byte[] bmiColors = null;
if (icm != null) {
bitCount = sampleBitsPerPixel;
bmiColors = new byte[(1<<icm.getPixelSize())*4];
for (int i=0;i<icm.getMapSize(); i++) {
bmiColors[i*4+0]=(byte)(icm.getBlue(i)&0xff);
bmiColors[i*4+1]=(byte)(icm.getGreen(i)&0xff);
bmiColors[i*4+2]=(byte)(icm.getRed(i)&0xff);
}
}
drawDIBImage(getPrintDC(), image,
destX, destY,
destWidth, destHeight,
srcX, srcY,
srcWidth, srcHeight,
bitCount, bmiColors);
}
protected void drawDIBImage(byte[] image,
float destX, float destY,
float destWidth, float destHeight,
float srcX, float srcY,
float srcWidth, float srcHeight,
int sampleBitsPerPixel,
IndexColorModel icm) {
int bitCount = 24;
byte[] bmiColors = null;
if (icm != null) {
bitCount = sampleBitsPerPixel;
bmiColors = new byte[(1<<icm.getPixelSize())*4];
for (int i=0;i<icm.getMapSize(); i++) {
bmiColors[i*4+0]=(byte)(icm.getBlue(i)&0xff);
bmiColors[i*4+1]=(byte)(icm.getGreen(i)&0xff);
bmiColors[i*4+2]=(byte)(icm.getRed(i)&0xff);
}
}
drawDIBImage(getPrintDC(), image,
destX, destY,
destWidth, destHeight,
srcX, srcY,
srcWidth, srcHeight,
bitCount, bmiColors);
}
protected void drawDIBImage(byte[] image,
float destX, float destY,
float destWidth, float destHeight,
float srcX, float srcY,
float srcWidth, float srcHeight,
int sampleBitsPerPixel,
IndexColorModel icm) {
int bitCount = 24;
byte[] bmiColors = null;
if (icm != null) {
bitCount = sampleBitsPerPixel;
bmiColors = new byte[(1<<icm.getPixelSize())*4];
for (int i=0;i<icm.getMapSize(); i++) {
bmiColors[i*4+0]=(byte)(icm.getBlue(i)&0xff);
bmiColors[i*4+1]=(byte)(icm.getGreen(i)&0xff);
bmiColors[i*4+2]=(byte)(icm.getRed(i)&0xff);
}
}
drawDIBImage(getPrintDC(), image,
destX, destY,
destWidth, destHeight,
srcX, srcY,
srcWidth, srcHeight,
bitCount, bmiColors);
}
protected void drawDIBImage(byte[] image,
float destX, float destY,
float destWidth, float destHeight,
float srcX, float srcY,
float srcWidth, float srcHeight,
int sampleBitsPerPixel,
IndexColorModel icm) {
int bitCount = 24;
byte[] bmiColors = null;
if (icm != null) {
bitCount = sampleBitsPerPixel;
bmiColors = new byte[(1<<icm.getPixelSize())*4];
for (int i=0;i<icm.getMapSize(); i++) {
bmiColors[i*4+0]=(byte)(icm.getBlue(i)&0xff);
bmiColors[i*4+1]=(byte)(icm.getGreen(i)&0xff);
bmiColors[i*4+2]=(byte)(icm.getRed(i)&0xff);
}
}
drawDIBImage(getPrintDC(), image,
destX, destY,
destWidth, destHeight,
srcX, srcY,
srcWidth, srcHeight,
bitCount, bmiColors);
}
protected void drawDIBImage(byte[] image,
float destX, float destY,
float destWidth, float destHeight,
float srcX, float srcY,
float srcWidth, float srcHeight,
int sampleBitsPerPixel,
IndexColorModel icm) {
int bitCount = 24;
byte[] bmiColors = null;
if (icm != null) {
bitCount = sampleBitsPerPixel;
bmiColors = new byte[(1<<icm.getPixelSize())*4];
for (int i=0;i<icm.getMapSize(); i++) {
bmiColors[i*4+0]=(byte)(icm.getBlue(i)&0xff);
bmiColors[i*4+1]=(byte)(icm.getGreen(i)&0xff);
bmiColors[i*4+2]=(byte)(icm.getRed(i)&0xff);
}
}
drawDIBImage(getPrintDC(), image,
destX, destY,
destWidth, destHeight,
srcX, srcY,
srcWidth, srcHeight,
bitCount, bmiColors);
}
protected void drawDIBImage(byte[] image,
float destX, float destY,
float destWidth, float destHeight,
float srcX, float srcY,
float srcWidth, float srcHeight,
int sampleBitsPerPixel,
IndexColorModel icm) {
int bitCount = 24;
byte[] bmiColors = null;
if (icm != null) {
bitCount = sampleBitsPerPixel;
bmiColors = new byte[(1<<icm.getPixelSize())*4];
for (int i=0;i<icm.getMapSize(); i++) {
bmiColors[i*4+0]=(byte)(icm.getBlue(i)&0xff);
bmiColors[i*4+1]=(byte)(icm.getGreen(i)&0xff);
bmiColors[i*4+2]=(byte)(icm.getRed(i)&0xff);
}
}
drawDIBImage(getPrintDC(), image,
destX, destY,
destWidth, destHeight,
srcX, srcY,
srcWidth, srcHeight,
bitCount, bmiColors);
}
protected void drawDIBImage(byte[] image,
float destX, float destY,
float destWidth, float destHeight,
float srcX, float srcY,
float srcWidth, float srcHeight,
int sampleBitsPerPixel,
IndexColorModel icm) {
int bitCount = 24;
byte[] bmiColors = null;
if (icm != null) {
bitCount = sampleBitsPerPixel;
bmiColors = new byte[(1<<icm.getPixelSize())*4];
for (int i=0;i<icm.getMapSize(); i++) {
bmiColors[i*4+0]=(byte)(icm.getBlue(i)&0xff);
bmiColors[i*4+1]=(byte)(icm.getGreen(i)&0xff);
bmiColors[i*4+2]=(byte)(icm.getRed(i)&0xff);
}
}
drawDIBImage(getPrintDC(), image,
destX, destY,
destWidth, destHeight,
srcX, srcY,
srcWidth, srcHeight,
bitCount, bmiColors);
}
protected void drawDIBImage(byte[] image,
float destX, float destY,
float destWidth, float destHeight,
float srcX, float srcY,
float srcWidth, float srcHeight,
int sampleBitsPerPixel,
IndexColorModel icm) {
int bitCount = 24;
byte[] bmiColors = null;
if (icm != null) {
bitCount = sampleBitsPerPixel;
bmiColors = new byte[(1<<icm.getPixelSize())*4];
for (int i=0;i<icm.getMapSize(); i++) {
bmiColors[i*4+0]=(byte)(icm.getBlue(i)&0xff);
bmiColors[i*4+1]=(byte)(icm.getGreen(i)&0xff);
bmiColors[i*4+2]=(byte)(icm.getRed(i)&0xff);
}
}
drawDIBImage(getPrintDC(), image,
destX, destY,
destWidth, destHeight,
srcX, srcY,
srcWidth, srcHeight,
bitCount, bmiColors);
}
protected void drawDIBImage(byte[] image,
float destX, float destY,
float destWidth, float destHeight,
float srcX, float srcY,
float srcWidth, float srcHeight,
int sampleBitsPerPixel,
IndexColorModel icm) {
int bitCount = 24;
byte[] bmiColors = null;
if (icm != null) {
bitCount = sampleBitsPerPixel;
bmiColors = new byte[(1<<icm.getPixelSize())*4];
for (int i=0;i<icm.getMapSize(); i++) {
bmiColors[i*4+0]=(byte)(icm.getBlue(i)&0xff);
bmiColors[i*4+1]=(byte)(icm.getGreen(i)&0xff);
bmiColors[i*4+2]=(byte)(icm.getRed(i)&0xff);
}
}
drawDIBImage(getPrintDC(), image,
destX, destY,
destWidth, destHeight,
srcX, srcY,
srcWidth, srcHeight,
bitCount, bmiColors);
}
protected void drawDIBImage(byte[] image,
float destX, float destY,
float destWidth, float destHeight,
float srcX, float srcY,
float srcWidth, float srcHeight,
int sampleBitsPerPixel,
IndexColorModel icm) {
int bitCount = 24;
byte[] bmiColors = null;
if (icm != null) {
bitCount = sampleBitsPerPixel;
bmiColors = new byte[(1<<icm.getPixelSize())*4];
for (int i=0;i<icm.getMapSize(); i++) {
bmiColors[i*4+0]=(byte)(icm.getBlue(i)&0xff);
bmiColors[i*4+1]=(byte)(icm.getGreen(i)&0xff);
bmiColors[i*4+2]=(byte)(icm.getRed(i)&0xff);
}
}
drawDIBImage(getPrintDC(), image,
destX, destY,
destWidth, destHeight,
srcX, srcY,
srcWidth, srcHeight,
bitCount, bmiColors);
}