Is this C++.NET?Minority said:Hi all,
If I use a picture box in a program and use the command:
pictureBox1->Load
to draw a picture to the pictureBox how do I then access the pixels of that picture and get the length and width back?
Thanks
int width = pictureBox1->Image->Width;
int height = pictureBox1->Image->Height;
// Convert to Bitmap to allow manipulation
Bitmap imageBitmap = new Bitmap(pictureBox1->Image);
int x = 0;
int y = 0;
Color pixelColour = Color::Black;
// Set a pixel to black
imageBitmap->SetPixel(x, y, pixelColour);
// Get the pixel's colour again
pixelColour = imageBitmap->GetPixel(x, y);
Whatever worksMinority said:I'm having to use the following instead of what you advised:
Bitmap imageBitmap = gcnew Bitmap(pictureBox1->Image);
imageBitmap.SetPixel(x, y, pixelColour);
Just do the following:Minority said:Anyhow, I can now draw to pixels and get their colours back, but how do I update the pictureBox image with the modified imageBitmap? I tried
pictureBox1->Load(imageBitmap);
pictureBox1->Image = imageBitmap;
Simple; use the R, G and B (and A if needed) properties of the Color returned by GetPixelMinority said:Last question, how do I get the individual RGB values for the pixels of an image?
Again, I'm not that familiar with C++, but as far as I know, Visual Studio doesn't allow multiple languages in one project. You can, however, have multiple languages in one solution. Just add another project to the solution in the appropriate language, and you can make calls between them easily.Minority said:Ahh I think I understand, it's possible to use multiple language types in one project? Selecting Windows Forms Application allows C++ code and C++ .NET code to be written into the same project?
I'm not really sure, because I don't know how your program works, but it would probably be sufficient just to use local variables where you need to.Minority said:Where should I declare the Bitmap imageBitmap so that it is accessible throughout the program?
Again, this is just C++ technicalities to me, but I guess you could try:Minority said:I'm still having trouble redrawing the bitmap to the pictureBox image though, it gives me an error:
cannot convert parameter 1 from 'System:rawing::Bitmap' to 'System:
rawing::Image ^'
Bitmap^ imageBitmap = gcnew Bitmap(pictureBox1->Image);
[/CODE
[QUOTE=Minority]When I got File->New->Project the project types are listed as Visual C++ and from there I select Windows Forms Application. There's no mention of .NET anywhere.[/QUOTE]
That would be because the whole of Visual Studio 2005 is .NET :)
Inquisitor said:Code:Bitmap^ imageBitmap = gcnew Bitmap(pictureBox1->Image);
imageBitmap->SetPixel(x,y,pixelColour);
&
pictureBox->Image = imageBitmap;
I'd definitely recommend getting a book, they're a huge help when it comes to learning a language (even if you already understand the gist of it). Perhaps one that focuses mainly on the .NET framework, rather than C++ itself?Minority said:I think I'm beginning to understand VS now, it has some things which are a lot nicer than Borland. I just need to understand this .NET malarky now, might have to get a good book.
Inquisitor said:I'd definitely recommend getting a book, they're a huge help when it comes to learning a language (even if you already understand the gist of it). Perhaps one that focuses mainly on the .NET framework, rather than C++ itself?
Kind of. .NET is a set of common libraries and standards that are shared by all .NET languages. C# could be considered the Microsoft equivelant of Java, as it is Microsoft's current flagship language, and was designed from the ground up around the .NET framework. It is in fact so similar to Java, that its internal development name was "I Can't Believe It's Not Java"Minority said:Yeh definitely. I have a pretty good understanding of C++ so picking up most languages isn't a problem but a book definitely helps. I do need toget to grips with .NET though.
Am I right in thinking its Microsofts version of Java essentially?