0
public class Loader {
public static byte[] loadImage(String path) {
Image image;
try {
image = new Image(new FileInputStream(path));
int width = (int) image.getWidth();
int height = (int) image.getHeight();
byte[] data = new byte[width * height * 4];
image.getPixelReader().getPixels(0, 0, width, height, PixelFormat.getByteBgraPreInstance(), data, 0, width * 4);
return data;
}catch(IOException e) {
e.printStackTrace();
System.exit(-1);
}
return null;
}
}
@Override
public void render(GraphicsContext gc) {
gc.clearRect(0, 0, width, height);
gc.getPixelWriter().setPixels(x++, 0, 819 ,720, PixelFormat.getByteBgraPreInstance(), data, 0, 819*4);
gc.getPixelWriter().setPixels(400, 0,819 ,720, PixelFormat.getByteBgraPreInstance(), data, 0, 819*4);
}
こんにちは、現時点では、JavaFxのPixelWriter/PixelReaderに問題があります。私はImageからPixelを読み込み、それをBufferに格納しようとします。その後、それをScreenにレンダリングします。しかしImageにはアルファ値が含まれていないので、透明ピクセルもありません。私はインターネットで数時間を探しましたが、私は答えを見つけることができません。おそらく、フォーマットに問題があります。 ありがとうございます。JavaFX PixelReaderアルファチャンネルが動作しない
フォーマットに問題がある可能性があります。 'Image'クラスでサポートされている4つのフォーマットのうち、2つだけが透過性を定義する仕組みを持っています。透明な色(α= 1またはalpha = 0のどちらか)を持つGIFと完全なアルファチャンネルを含むPNGです。 BMPまたはJPGファイルを読む場合、アルファ値はありません。 PNGファイルを読み込んだ場合でも、元のファイルにアルファチャンネルがない場合は、異なるピクセルのアルファにバリエーションは表示されません。 – Itai
既にPNGファイルをチェックして、それはアルファチャンネルを持っています。とにかくおかげでAlpha Channel.Butで画像を読んでいることを知っていると言っても忘れてしまった。 –