Reputation: 13
I need to develop a console application in C# which gets the name of a bitmap image as a parameter in main function. The application must analyze the image content from the file and display to console the type of geometric shape and its color. Conditions: - Only uncompressed BMP files containing only primary forms: rectangle, square and triangle - Images contain one form or more - Forms are primary colors - RGB and white background is no transparency - Can not be used other libraries than those provided by Visual Studio for C # - The application can receive on the command line one picture or more
So, i'm using Drawing library and i want to make a matrix of bmp's pixels. After that, i'll cross this matrix and i'll discover the figure inside the image. I find the first pixel that's not white (only the background is white) and then I trace the colored path right and down(two figures cannot intersect). If they have the same length it's a triangle or a square, else it is a triangle or rectangle. I dig more to find out which of them is it. I remove the shape and i repeat because there can be more than one figure. Everything looks great, but i'm very new at this, and i ned help on implementing this thing. Can anyone, please, help me?
Thank you!
` using System;
using System.Drawing;
using System.Drawing.Imaging;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Bitmap bmp = new Bitmap("img1.bmp");
int h, w;
h = bmp.Height;
w = bmp.Width;
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
System.Drawing.Imaging.BitmapData bmpData =bmp.LockBits
(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
bmp.PixelFormat);
`
Upvotes: 1
Views: 1147
Reputation: 3299
System.Drawing.Bitmap
has this method:
public Color GetPixel ( int x, int y );
Apart from that, it appears that determining whether the bitmap represents a triangle, square, or rectangle requires quite a bit more tenacity and resourcefulness than finding that method. Are you sure you are up to it?
Upvotes: 0