Jump to content
  • Advertisement
Sign in to follow this  
TeSsL

reading from Arraylist

This topic is 3278 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am currently trying to do an imaging project with c#. However, encounter some problems with viewing the results. first, i have got a couple of points(consisting of x,y, level of image) stored in a arraylist. but i am not sure how to read the coordinates stored. I tried printing out list[count] but what i got was "points"(i.e. name of the created data type) instead of the actual value. and it gives error when i try "list[count].x". Its my first time trying to use arraylist so not sure how it works. Next, i am trying to get the points above and mark a cross(or any indications) on the bitmap image.How should i go about doing it? Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
Reading the error message would work here.

If "count" is the number of the elements on the "list", list[count] points past the last element. Also note that the ArrayList also has a Count property which automatically keeps track of the number of the elements on the list.

As for drawing to a bitmap, you can get a Graphics object out of the bitmap and use its methods to draw stuff, including lines (for crosses). See Graphics.FromImage on MSDN.

Share this post


Link to post
Share on other sites
No actually i am using a loop to get all the point from 0 to count. But instead of giving me the element inside, it prints Dscalespace+scalepoint, which is the name of the class for the element type.. Why does it gives me the type instead of the real value?

and if i change to list[count].x,
it says: 'object' does not contain a definition for 'x' and no extension method 'x' accepting a first argument of type 'object' could be found.
Hmmm. btw what is a internal class? cause i realize the scalepoint class is defined as an internal class. anything do with it?

Share this post


Link to post
Share on other sites
The default implementation of ToString() returns the name of the type so that's why you're seeing that when you try to print out list.

The reason you get the "'object' does not contain a definition for 'x'" error is because ArrayList works with objects, so list is returning an object. You can cast to the correct type and it should work: ((Point) list).x

In reality, you really shouldn't be using ArrayList in C# 2.0+. Instead, you should be using the generic List<T>. As in, List<Point>.

Share this post


Link to post
Share on other sites
If you're using the ToString of an object that doesn't override it to show you some meaningful data, it returns the object's type name by default.

How do you declare the list variable?

An internal class is a class that is only usable from within the same assembly that it was defined in. I don't believe this has anything to do with your problem.

Share this post


Link to post
Share on other sites
Thanks i got it working using a List. And got my crosses drawn making use of the drawline function=D

But now i got another problem. The code converts a image into a different type by extracting the pixel and does scaling and blurring to it. How do i convert it back to bitmap(or other image type which allows me to print on a picturebox)? I wanted to try converting via extracting pixels and go the reverse way is it possible cause i keep getting different errors?
Mainly because:
1. The setPixel method requires system.drawing.color but what i have is only the a double which is gotten from the average of the rgb.
2. Bitmap doesn't seem to let me create a new empty bitmap. It requires an original image.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!