1

Hi I'm trying to convert an application in Java from C# and this is the only problem I am having .. : Sidenote: That Bitmap class is a class I have made.

Java Code:

        for (int x = 0; x < xTiles; x++) {
            for (int y = 0; y < yTiles; y++) {
                result[x][y] = new Bitmap(w, h);
                bi.getRGB(bx + x * w, by + y * h, w, h,
                        result[x][y].pixels, 0, w);
            }
        }

What I have in C#:

           for (int X = 0; X < XTiles; X++)
            {
                for (int Y = 0; Y < YTiles; Y++)
                {
                    Result[X,Y] = new Bitmap(W, H);
                }
            }

But I cant seem to find the method or howTo do that in C# (getRGB). Its the only thing stopping from what I need to do to work. Thanks!

1 Answers1

0

If you have a Bitmap object created, you can use bitmap.GetPixel(int x, int y) to get the Color (struct) at the given {x, y} coordinate.
You can also use bitmap.SetPixel(int x, int y, Color color) to set the color.

If you need to do these pixel operations fast, then google "LockBits".

Edit:
Oh, Bitmap is your own custom class?
Use System.Drawing.Bitmap instead and you'll have access to the methods that I specified.

Edit 2:
Yeah, the BufferedImage equivalent is System.Drawing.Bitmap, so you may need to rename your custom C# Bitmap class (or not).

Bradley Odell
  • 1,248
  • 2
  • 15
  • 28