getPixel -Method - Como obtenho o valor R do RGB?
-
20-09-2019 - |
Pergunta
Eu tenho uma imagem em escala de cinza e quero escanear os pixels da imagem e é isso que recebo:
var i:int;
var j:int;
for (i = 0; i < img.contentWidth ; i++)
{
for(j = 0; j < img.contentHeight; j++){
pixeldaten.addItem({x:i,y:j,pixel:bmd.getPixel(i,j)});
}
}
Mas a tabela não se parece com valores de RGB. (R, b e g deve ser o mesmo)
: exemplo
Solução
getpixel deve devolver o valor hexadecimal do pixel, você pode fazer algo como
// Obtenha o valor vermelho
bmd.getPixel(i,j) >> 16
Outras dicas
//for Image processing
Bitmap myBitmap = new Bitmap(CurrentBitmap);
int imgH = myBitmap.Height;
int imgW = myBitmap.Width;
ARed = new double[imgH, imgW];
AGreen = new double[imgH, imgW];
ABlue = new double[imgH, imgW];
doubles = new double[imgH, imgW];
var max = new double[imgH, imgW];
var min = new double[0, 0];
//seperating each RGB components
for (int x = 0; x < imgH; x++)
{
for (int y = 0; y < imgW; y++)
{
Color color = myBitmap.GetPixel(x, y);
// things we do with pixelColor
//ARed[x][y] = myBitmap.GetPixel >> 16;
ARed[x, y] = color.R;
ABlue[x, y] = color.B;
AGreen[x, y] = color.G;
max[x, y] = ARed[x, y];
}
}
Bitmap bmp = new Bitmap(pictureBox1.Image);
bmp.getPixel(i,j).R
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow