簡體   English   中英

BufferImage:如何確定像素顏色

[英]BufferImage: How to certainly determine a pixel color

我有一個以PNG格式編碼的位圖。 如何確定黑色在哪里,白色在哪里?

            final int[] p = new int[1];
            int iter = 0;
            for (int i = 0; i < image.getWidth(); i++) {
                for (int j = 0; j < image.getHeight(); i++) {
                    pixels[iter] = image.getData().getPixel(i, j, p)[0];
                    iter++;
                }
            }

每個像素總是返回1。

根據圖像的編碼方式,像素被打包為一個整數,例如Sa,例如BufferedImage.TYPE_4BYTE_ABGR,高字節為alpha,然后為藍色,綠色然后為紅色。

BufferedImage image = ImageIO.read(file);
// Getting pixel color by position x=100 and y=40 
int clr=  image.getRGB(100,40); 
int  red   = (clr & 0x00ff0000) >> 16;
int  green = (clr & 0x0000ff00) >> 8;
int  blue  =  clr & 0x000000ff;

紅色,綠色和藍色將是x = 100和y = 40時像素的RGB值

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM