I was making a 2d map editor for my square tile platformer game, when I realized I could really use an image editor with its abilities to repaint adjacent pixels and many mo
public Color[][] getBitmapColorMatrix(string filePath)
{
Bitmap bmp = new Bitmap(filePath);
Color[][] matrix;
int height = bmp.Height;
int width = bmp.Width;
if (height > width)
{
matrix = new Color[bmp.Width][];
for (int i = 0; i <= bmp.Width - 1; i++)
{
matrix[i] = new Color[bmp.Height];
for (int j = 0; j < bmp.Height - 1; j++)
{
matrix[i][j] = bmp.GetPixel(i, j);
}
}
}
else
{
matrix = new Color[bmp.Height][];
for (int i = 0; i <= bmp.Height - 1; i++)
{
matrix[i] = new Color[bmp.Width];
for (int j = 0; j < bmp.Width - 1; j++)
{
matrix[i][j] = bmp.GetPixel(i, j);
}
}
}
return matrix;
}
I think I've done something similar once. Here's a code snippet of what I was doing:
public static void main(String[] args) {
try {
String path = "src/colors.jpg";
BufferedImage image = ImageIO.read(new File(path));
int w = image.getWidth();
int h = image.getHeight();
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
Color c = new Color(image.getRGB(x, y));
int red = c.getRed();
int green = c.getGreen();
int blue = c.getBlue();
countColor(red, green, blue);
totalCount++;
}
}
printColors();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
In the inner for loop you can put something into an array[i][j]. (If that is what you're looking for)
Well, if I understood correctly, you want to iterate through the pixels in the image, perform some kind of test, and if it passes you want to store that pixel in an array. Here´s how you could do that:
using System.Drawing;
Bitmap img = new Bitmap("*imagePath*");
for (int i = 0; i < img.Width; i++)
{
for (int j = 0; j < img.Height; j++)
{
Color pixel = img.GetPixel(i,j);
if (pixel == *somecondition*)
{
**Store pixel here in a array or list or whatever**
}
}
}
Don´t think you need anything else. If you need the specific RGB values you can get them from the corresponding methods in the pixel object.