Javaの何がC#PixelFormat'sのメンバーと一致しますか?.Net PixelFormatにはJavaに相当するものがありますか?
つまり、Format24bppRgbはBufferedImage.TYPE_INT_RGBに一致しますか?
ここに私のコードです。私は赤と青の色がそれにスワップされるBufferedImageを作成した後
int sizeBytes = width * height;
DataBufferByte dataBuffer = new DataBufferByte(myImageBytes, sizeBytes);
WritableRaster raster = Raster.createInterleavedRaster(dataBuffer, // dataBuffer
width, // width
height, // height
width * 4, // scanlineStride
4, // pixelStride
new int[]{0, 1, 2, 3}, // bandOffsets
null); // location
java.awt.image.ColorModel colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), // ColorSpace
new int[]{8, 8, 8, 8}, // bits
true, // hasAlpha
false, // isPreMultiplied
ComponentColorModel.TRANSLUCENT, DataBuffer.TYPE_BYTE);
BufferedImage result = new BufferedImage(colorModel, raster, false, null);
:私は、私はこのようなBufferedImageを作成しています。ネットのピクセルフォーマット= Format32bppArgb を持っている画像を得ました。
次に、私は
BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
WritableRaster r = result.getRaster();
int[] pixels = byteToInt(bytes);
r.setPixels(0, 0, width, height , pixels); // ! Here an exception occures, because after I converted the byte array to int one the width becomes too long.
バイト配列に従うよう画像を作成しようとしたに
private int[] byteToInt(byte[] pixels) {
int[] ints = new int[pixels.length/3];
int byteIdx = 0;
for (int pixel = 0; pixel < ints.length; pixel++) {
int red = (int) pixels[byteIdx++] & 0xFF;
int green = (int) pixels[byteIdx++] & 0xFF;
int blue = (int) pixels[byteIdx++] & 0xFF;
int rgb = (red << 16) | (green << 8) | blue;
ints[pixel] = rgb;
}
return ints;
}
色が今も元気になり、この方法で変換したが、私は例外を得た
java.lang.ArrayIndexOutOfBoundsException: 27600
at sun.awt.image.ByteInterleavedRaster.setPixels(ByteInterleavedRaster.java:1106)
小さい幅(たとえば幅/ 3)を使用すると、色はよく見えますが、画像自体は小さくなります。
私はこの問題を抱えています。どんな助けもありがとうございます。ありがとう。
私は通常、画像として配列を表示するために使用するコードですまたはそれがもはや有効でない場合は、誰もが問題が解決されたことを知るように、最も適切な回答を選択するために「チェック」してください。ありがとう。 – wattostudios