本文整理汇总了Java中ar.com.hjg.pngj.chunks.PngChunkTRNS.setGray方法的典型用法代码示例。如果您正苦于以下问题:Java PngChunkTRNS.setGray方法的具体用法?Java PngChunkTRNS.setGray怎么用?Java PngChunkTRNS.setGray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ar.com.hjg.pngj.chunks.PngChunkTRNS
的用法示例。
在下文中一共展示了PngChunkTRNS.setGray方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeMaskedTwoBitPng
import ar.com.hjg.pngj.chunks.PngChunkTRNS; //导入方法依赖的package包/类
public static void writeMaskedTwoBitPng(Bitmap blackAndWhiteBitmap, OutputStream stream, boolean transparentBlack)
{
LightBitmap lightBitmap = new LightBitmap(blackAndWhiteBitmap);
ImageInfo imageInfo = new ImageInfo(lightBitmap.getWidth(), lightBitmap.getHeight(), 1, false, true, false);
PngWriter pngWriter = new PngWriter(stream, imageInfo);
PngChunkTRNS transparencyChunk = pngWriter.getMetadata().createTRNSChunk();
transparencyChunk.setGray(transparentBlack ? 0 : 1);
for (int y = 0; y < lightBitmap.getHeight(); y++)
{
ImageLineByte imageLine = new ImageLineByte(imageInfo);
for (int x = 0; x < lightBitmap.getWidth(); x++)
{
int pixel = lightBitmap.getPixel(x, y) & 0x00FFFFFF;
int r = Color.red(pixel);
imageLine.getScanline()[x] = (byte) (r > 255 / 2 ? 1 : 0);
}
pngWriter.writeRow(imageLine, y);
}
pngWriter.end();
}
示例2: encodeIndexedPNG
import ar.com.hjg.pngj.chunks.PngChunkTRNS; //导入方法依赖的package包/类
public byte [] encodeIndexedPNG (int [] pixels, int width, int height, boolean color, int bits) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int [] palette = getPalette();
boolean alpha = Color.alpha(palette[0]) == 0;
boolean grayscale = !color;
//Log.d(TAG, "encodeIndexedPNG: color = "+color +", alpha ="+alpha+", grayscale = "+grayscale);
//ImageInfo imageInfo = new ImageInfo(width, height, bits, alpha, grayscale, color);
ImageInfo imageInfo = new ImageInfo(width, height, bits, false, grayscale, color);
PngWriter writer = new PngWriter(bos, imageInfo);
writer.getPixelsWriter().setDeflaterCompLevel(9);
if (color) {
PngChunkPLTE paletteChunk = writer.getMetadata().createPLTEChunk();
paletteChunk.setNentries(palette.length);
for (int i = 0; i < palette.length; i++) {
int c = palette[i];
paletteChunk.setEntry(i, Color.red(c), Color.green(c), Color.blue(c));
}
}
if (alpha) {
PngChunkTRNS trnsChunk = writer.getMetadata().createTRNSChunk();
if (color) {
trnsChunk.setIndexEntryAsTransparent(0);
} else {
trnsChunk.setGray(1);
}
}
else {
quantize(pixels, imageInfo.cols);
}
ImageLineInt line = new ImageLineInt(imageInfo);
for (int y = 0; y < imageInfo.rows; y++) {
int [] lineData = line.getScanline();
for (int x = 0; x < imageInfo.cols; x++) {
int pixel = pixels[y * imageInfo.cols + x];
//lineData[x] = getNearestColorIndex(pixel) ^ (x % 2) ^ (y % 2);
lineData[x] = getNearestColorIndex(pixel);
}
writer.writeRow(line);
}
writer.end();
return bos.toByteArray();
}
示例3: encodeIndexedPNG
import ar.com.hjg.pngj.chunks.PngChunkTRNS; //导入方法依赖的package包/类
public byte [] encodeIndexedPNG (int [] pixels, int width, int height, boolean color, int bits) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int [] palette = getPalette();
boolean alpha = Color.alpha(palette[0]) == 0;
boolean grayscale = !color;
//Log.d(TAG, "encodeIndexedPNG: color = "+color +", alpha ="+alpha+", grayscale = "+grayscale);
//ImageInfo imageInfo = new ImageInfo(width, height, bits, alpha, grayscale, color);
ImageInfo imageInfo = new ImageInfo(width, height, bits, false, grayscale, color);
PngWriter writer = new PngWriter(bos, imageInfo);
writer.getPixelsWriter().setDeflaterCompLevel(9);
if (color) {
PngChunkPLTE paletteChunk = writer.getMetadata().createPLTEChunk();
paletteChunk.setNentries(palette.length);
for (int i = 0; i < palette.length; i++) {
int c = palette[i];
paletteChunk.setEntry(i, Color.red(c), Color.green(c), Color.blue(c));
}
}
if (alpha) {
PngChunkTRNS trnsChunk = writer.getMetadata().createTRNSChunk();
if (color) {
trnsChunk.setIndexEntryAsTransparent(0);
} else {
trnsChunk.setGray(1);
}
}
else {
quantize(pixels, imageInfo.cols);
}
ImageLineInt line = new ImageLineInt(imageInfo);
for (int y = 0; y < imageInfo.rows; y++) {
int [] lineData = line.getScanline();
for (int x = 0; x < imageInfo.cols; x++) {
int pixel = pixels[y * imageInfo.cols + x];
lineData[x] = getNearestColorIndex(pixel);
}
writer.writeRow(line);
}
writer.end();
return bos.toByteArray();
}