C
C#16mo ago
Sh3de

❔ Get Pixels cords from Image by their color

Hey, I'm writing a game and I need to get the pixels cords by their colors from an Image, I tried using Bitmap but it cannot be converted from System.drawing.Image to System.Drawing.Bitmap. There is any other way to get pixel cords by their colors ?
11 Replies
Buddy
Buddy16mo ago
huh? If you are writing a game, don't you already have the pixel coords? Either way, you can use GetPixel / SetPixel. But they are not fast.
Sh3de
Sh3de16mo ago
No, I will explain, I'm making pacman in my own terms .. To make the map(gameCanvas) I want to draw image that's every color will determent the objects, for example: Blue for walls Yellow for coins Red for traps and more..
Buddy
Buddy16mo ago
I wouldn't recommend checking object by color value. But instead use classes of their own.
Sh3de
Sh3de16mo ago
And do you have any idea for making the game borders ? because I want to find smarter way then building the game borders manually In the game code behind
Buddy
Buddy16mo ago
I personally would make a system to easily make maps. That way I can make my own editor in the future. Although Pacman doesn't really have "other maps" it's just a single map But I would still recommend to use classes instead of color values (including borders) That way you aren't limited by colors
Sh3de
Sh3de16mo ago
oh I get it, but if I don't have time to make map editor ? I have to hand over the project soon, would you recommend me in this case to just build in manually ?
Buddy
Buddy16mo ago
If it's an assignment, I wouldn't want to remake the entire thing. I would just go with what I have. So as I mentioned before, the way to check a pixel value from an image is via the method GetPixel. It's not the fastest but it will do. There is LockBits that allows you to go a little more low level, but it's significantly faster. https://learn.microsoft.com/en-us/dotnet/api/system.drawing.bitmap.lockbits?view=dotnet-plat-ext-7.0 Just not recommended for a beginner.
Sh3de
Sh3de16mo ago
That's why I'm using traps instand of ghosts it more fast and easy to make them then the original ghosts The thing that's i cant convert the image to bitmap, that's why i cant check the pixels cords by their colors I saw in the link right now it may work
Buddy
Buddy16mo ago
A bitmap takes in an image in the constructor. https://learn.microsoft.com/en-us/dotnet/api/system.drawing.bitmap.-ctor?view=dotnet-plat-ext-7.0#system-drawing-bitmap-ctor(system-drawing-image) But I wouldn't want to initialize a new bitmap each frame.
Sh3de
Sh3de16mo ago
there is any thing else I can do to make the map unmanually ? I don't think I will finish in time with the method I had in mind
Accord
Accord16mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ Storing & retrieving face encodings to compareWhat's the best way to store face encodings (an array of size 128 and type float64) in a database an❔ New to C# and am trying to make a Minesweeper console appI am having trouble with my "UpdateBoard" method and I can not seem to figure out what the problem i❔ System.Data.OleDb.OleDbException: 'Could not find installable ISAM.' errorHi anyone can help me? i start the test and i got System.Data.OleDb.OleDbException: 'Could not find ❔ Accounting for Daylight Savings Time skips at runtimeMy Discord bot I am developing has a reminder system which utilizes <https://github.com/robbell/nChr✅ I need to put an invalid choice in my programI need to make the program repeat if they did not input a valid response of yes or no❔ My project runs successfully but doesn't load ( works fine when I run it without debugging )my project was working fine but suddenly whenever I run it it keeps loading without showing anythingOnly assignment, call, increment, decrement, await, and new object expressions can be used as a statim a noob and why cant i make my console make a beep sound? I didnt understand the error msg❔ multiple Async responsesSo im trying to use async for the first time, i am making a few api requests one after the other, thInvoke Event on boolean set in systemclassI have my own TcpClient class that inherits TcpClient and I wanna invoke an event when one of the bo❔ How to properly handle exceptions between API controller and service layer?I'm creating an API and I'm having trouble figuring out how to properly catch errors between my serv