473,394 Members | 1,811 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Questions: Tons of Images; Arrays cross-class.

Samishii23
246 100+
First, images...
I have a project that, at this time and version I am working with, I have 648 main stay images, so to say, plus another 100 or so in side features.

They are going to stored in a outside .dll. Though I can't figure out if I want to use the Resources feature with C# rather then the "Direct" calling if you will. I have, in many Learning projects in the past have just used the direct call "C:\\Image.jpg" with success, even outside my PC. So I could do that, as I have already have all the file names in my arrays awaiting the code to make use of them.

Question: Should I go with the Resource feature? Is this the best way to go about this with all these images? =P

Second, my program has a separate .dll holding all the text data for the program. The .cs file is over 120k as it is and I'm still not done filling all the data. Mind you this is simply a namespace, and seperate data classes, then the data. Thats it.

How should I go about calling the arrays from separate namespaces and classes? I can't figure it out. Heres an example of what I was doing earlier with no success.

Expand|Select|Wrap|Line Numbers
  1. using System; using System.Collections.Generic; using System.Drawing;
  2.  
  3. namespace GeneralLibrary {
    public class ImageLib {
    System.Drawing.Image[] FrontIcon = new System.Drawing.Image[] { /*Array of 10 Images in Resources */ };
    ImageLib Temp = new ImageLib();
    static public Bitmap GetFrontIcon(int I) {
    return Temp.FrontIcon[i];
  4. }}}
and this has failed, bringing up the error "An object reference is required for the non-static field, method, or property".
I'm at a loss as to how to go about this problem. =\
Oct 20 '09 #1
15 2472
GaryTexmo
1,501 Expert 1GB
"An object reference is required for the non-static field, method, or property"
GetFrontIcon is a static method that tries to return Temp, a non-static member. I hope that helps! I don't really have anything to offer on the other topic, except maybe you should reevaluate your image allocation. Do you need to have all 648 images loaded at the same time?

I don't know anything about your program so it's hard for me to speculate, but it might be worthwhile to only load those images you'll be using for any given state in your code. When you go from one state to another, eat a bit of a loading time and cache the images you'll need for that state. Not always necessary, but it's something to think about at any rate.
Oct 20 '09 #2
Samishii23
246 100+
Ok, I'll be a little more specific...

Should I use an ImageList to cache the images I need for the instance? That was one of my original thoughts. But Im cornered with this again, lol...

I don't know which way would be more efficient, or probable. I already have a array with images named out in their specific category, and I have a variable with the directory string... I have done that method of calling an image from a .dll before on a seperate computer to see if it worked, and there wasn't an error...
Do I just "Embed" all the files into the .dll file, and do I just call them like (for example) this:
Expand|Select|Wrap|Line Numbers
  1. List<Image> ImgCache = new List<Image>();
  2. // 1 way
  3. ImgCache.add(@"C:\\Project\\images\\icon_1.jpg");
  4. // Another way using the Resource system
  5. ImgCache.add(global::GeneralData.Properties.Resources.icon_1);
Also...
How do I get data from an entirely different NameSpace / Class that is in an array. Am I going to have to make a method in that Class to push out the data to be class / method I need the data at?

Also Gary: I tried removing the Static from the method from above that was giving me the error. No change, error wise or where the error was located in the code.
Oct 21 '09 #3
GaryTexmo
1,501 Expert 1GB
No I meant put static in :) You had a static method trying to access a non-static member. So when that static method tried to look at the contents of the non-static member, it's null because it hasn't been instantiated. An easy fix would be to make the non-static member a static member.

I guess if you're loading everything with a DLL, it's already in memory. The alternative I was talking about was to load it directly from a file when needed (hence the caching). As I said, either way would work for you, I was just suggesting an alternative :)

As for your actual storage type... it depends on how you're looking it up I guess. If you'll be going through every image anyway, you might as well just use a List, then parse the list and put each image where it needs to go. If you'll be looking up an image by name as you need it, maybe use a hash table with the image name as the key for fast retrieval. This part really depends on how you code your program.
Oct 21 '09 #4
Samishii23
246 100+
Lol. Im still new to C#, and pretty much .exe making in general. So I have no idea other then the little bits and peices I've been told.

I'd rather all those image files be in one centralized location without being visible to the end-user. Is there a way to do that without having all the files in another folder rather then in a dll?

Im open for suggestions! :)
Oct 21 '09 #5
GaryTexmo
1,501 Expert 1GB
I don't know of any other way to hide resource files from the user other than to embed them in a DLL, which is what you were doing already. I think once a DLL is loaded, it's in memory... but I'm no expert on how that stuff works. Someone else may have some comments on that.

Out of curiosity, why do they need to be hidden from the end user? I mean, all the user does is run the executable, any resources the program uses live in the directory and your average user shouldn't care. If some sneaky person decides they want to change a few of the images, the absolute worst they'll do is mess up the program form themselves... which is really their own fault.

To be honest, having them live in a directory makes things easier for you. Images change... instead of having to recompile the DLL every time you need to update content, you can just replace files.

Still, it's your project, do it how you like. I'm just trying to offer alternatives/discussion points. At the end of the day, just experiment. You know what you want to do, so try some things and if they work out, implement them. If they don't, try another approach. I think you've got a lot to work with and you seem like you have a good handle on what you want to accomplish. If images and text embedded in DLLs turn out to be what works best for you, then there ya go :)
Oct 21 '09 #6
Samishii23
246 100+
Ok Gary. Going to give storing the images an a the .exe dir and see how that goes in load time, and resources...

Now. I have a side Class Library where I'll be holding all my "Current Version" data. Since there'll be multiple version entries, and Im an archiver, if you will, I'll be holding all the excess data in the outside .dll, so I can just recomile the .exe for bugs and new features, exc and the .dll when a new version comes out.

So basicly this the the Librarys code.
Expand|Select|Wrap|Line Numbers
  1. namespace v322 {
  2.  // I'll have 10 of theses
  3.  public class DataClass1 {
  4.   // There will be 44 entries in my project
  5.   // But for the sake of this, only a couple
  6.   int[] DataNumber = new int[] { 0, 2, 3, 2 };
  7.   string[] DataTitle = new string[] { null, "First", "Second", "Third" };
  8.   string[] DataIcon = new string[] { null, "1.jpg", "2.jpg", "3.jpg" };
  9.   string[][] DataDisc = new string[][] {
  10.    null,
  11.    new string[] { "Sub Disc 1", "Sub Disc 2" };
  12.    new string[] { "Sub Disc 1", "2", "3" };
  13.    new string[] { "1","2" };
  14.   };
  15.  }
  16. }
I've added the references to my main project. I have been able to get any data straight up from the DataClass in my main project. I'm lost as to how to retrieve the data without a Method in the DataClass to return each array item. I have once before tried to return the entire array variable without success...

Is there a way I can return the entire array object? Or maybe a way to access the arrays in the main project with a way Im not seeing??
Oct 21 '09 #7
GaryTexmo
1,501 Expert 1GB
I'm like 99% sure that members are private by default in C#, so that would explain why you can't access any of your members in the DataClass1 class.

Expand|Select|Wrap|Line Numbers
  1. public class MyConstants
  2. {
  3.   public double PI = 3.141592654;
  4. }
You can also create public properties to get the data out...

Expand|Select|Wrap|Line Numbers
  1. public class Person
  2. {
  3.   private string m_firstName = "";
  4.  
  5.   public string FirstName
  6.   {
  7.     get { return m_firstName; }
  8.     set { m_firstName = value; }
  9.   }
  10. }
The first approach might be what you want since it's a data storage class (more like a struct, really), but it's up to you.
Oct 21 '09 #8
Samishii23
246 100+
Can't you do:
Expand|Select|Wrap|Line Numbers
  1. class Data {
  2.    public string name { get; set; }
  3. }
???
I've seen tutorials talk about this a few times but when I tried to do it, theres a compiler error. lol Pretty pointless to put it in a tutorial if it doesn't work!! Heh
Oct 21 '09 #9
GaryTexmo
1,501 Expert 1GB
Supposedly you can... they call it auto-implemented properties, but I could never get it to work. I typed that exact same thing into my copy of VS and it wouldn't do it. Maybe it's something new that VS 2005 (what I have at work) doesn't support, and what C# 2008 Express Edition (that I have at home) doesn't offer.

I have absolutely no idea how that's supposed to work... so I just do it manually, which isn't so bad :)
Oct 21 '09 #10
Samishii23
246 100+
Data Code, Basicly I would like each of these variables to be passed through the GetMe function...
Expand|Select|Wrap|Line Numbers
  1. namespace CalcData
  2. {
  3.     public class GeneralData
  4.     {
  5.         private GeneralData() {}
  6.  
  7.         // Image Directory Declarations
  8.         string DirIcon = Environment.CurrentDirectory + "\\icons\\";
  9.         string DirOther = Environment.CurrentDirectory + "\\img\\";
  10.         // Talent Icon Width / Height
  11.         public readonly int DIcoW = 32;
  12.         public readonly int DIcoH = 32;
  13.         // Talent Tree Image Width / Height
  14.         public readonly int DTreeBGW = 580;
  15.         public readonly int DTreeBGH = 210;
  16.         // StartUp Form Window Width / Height
  17.         public readonly int SUWindowW = 358;
  18.         public readonly int SUWindowH = 187;
  19.         // Form Window Normal Width / Height
  20.         public readonly int DWindowW = 791;
  21.         public readonly int DWindowH = 610;
  22.         // Talent Tree X and Y Positions
  23.         public readonly int DTreeX = 3;
  24.         public readonly int[] DTreeY = new int[] { 2, 218, 434 }; // Trees 1, 2, 3 Respectively
  25.         // Talent Icon X and Y Positions
  26.         public readonly int[] DTIconY = new int[] { 12, 64, 116, 168, 220, 272, 324, 376, 428, 480, 532 }; // 11 rows; applys to all 3 trees
  27.         public readonly int[] DTIcon1X = new int[] { 12, 64, 116, 168 }; // Tree 1; 4 Rows
  28.         public readonly int[] DTIcon2X = new int[] { 225, 277, 329, 381 }; // Tree 2; 4 Rows
  29.         public readonly int[] DTIcon3X = new int[] { 441, 493, 545, 597 }; // Tree 3; 4 Rows
  30.         // Start Up Icon X and Y Locations
  31.         public readonly int[] SUIconY = new int[] { 10, 76 }; // 2 Rows
  32.         public readonly int[] SUIconX = new int[] { 10, 76, 144, 210, 276 }; // 5 Columns
  33.  
  34.         public object GetMe(string What, int I)
  35.         {
  36.             switch (What)
  37.             {
  38.                 case "dir_icon": return DirIcon;
  39.                 case "dir_img": return DirOther;
  40.                 default: return null;
  41.             }
  42.         }
  43.     }
  44. }
This is all I've coded so far...
Expand|Select|Wrap|Line Numbers
  1. if (!Directory.Exists(CalcData.GeneralData.GetMe("dir_icon",0))) {
  2.    MessageBox.Show("Missing the icon directory!");
  3.    Application.Exit();
  4.    }
Error: Argument '1': Can not convert object object into string.

Added ToString() to the end of GetMe()...
Error: An object reference is required for the non-static field, method, or property 'CalcData.GeneralData.GetMe(string, int)

Added static to the method:
Expand|Select|Wrap|Line Numbers
  1. public static object GetMe(string What, int I)
Same Error as above...

Im lost. =\
Oct 22 '09 #11
GaryTexmo
1,501 Expert 1GB
I dunno if I'm reading this right, but you're still mixing statics and non-statics...

It's either...

Expand|Select|Wrap|Line Numbers
  1. public static Constants
  2. {
  3.   public static string Name = "GaryTexmo";
  4.  
  5.   public static object GetMe(string description)
  6.   {
  7.     object obj = null;
  8.     switch (description.ToLower())
  9.     {
  10.       case "name":
  11.         obj = this.Name;
  12.         break;
  13.     }
  14.   }
  15. }
  16.  
  17. [[ main method ]]
  18. {
  19.   Console.WriteLine(Constants.Name);
  20.   Console.WriteLine(Consants.GetMe("name"));
  21. }
... or ...

Expand|Select|Wrap|Line Numbers
  1. public Constants
  2. {
  3.   public string Name = "GaryTexmo";
  4.  
  5.   public Constants() { }
  6.  
  7.   public object GetMe(string description)
  8.   {
  9.     object obj = null;
  10.     switch (description.ToLower())
  11.     {
  12.       case "name":
  13.         obj = this.Name;
  14.         break;
  15.     }
  16.  
  17.     return obj;
  18.   }
  19. }
  20.  
  21. [[ main method ]]
  22. {
  23.   Constants myConstants = new Constants();
  24.  
  25.   Console.WriteLine(myConstants.Name);
  26.   Console.WriteLine(myConsants.GetMe("name"));
  27. }
See the difference?

(I think I coded that right, I didn't run it through a compiler... let me know if it still gives you troubles and I'll putter around with it. I'm hoping to give you enough "hints" that you'll sort it out on your own, so it'll stick with you :D)
Oct 23 '09 #12
Samishii23
246 100+
Expand|Select|Wrap|Line Numbers
  1. static string DirIcon = Environment.CurrentDirectory + "\\icons\\";
  2. static string DirOther = Environment.CurrentDirectory + "\\class\\";
  3.  
  4. public static object GetMe(string What, int I) {
  5.   //object NObj = null;
  6.   switch (What)
  7.   {
  8.     case "dir_icon": return DirIcon;
  9.     case "dir_img": return DirOther;
  10.     default: return null;
  11.   }
  12. }
Expand|Select|Wrap|Line Numbers
  1. public void DoCheck() {
  2.   // DoCheck() - Checking to see if files needed are there.
  3.   if (!Directory.Exists(GeneralData.GetMe("dir_icon",0).ToString()))
  4.   {
  5.     MessageBox.Show("Missing the icon directory!");
  6.     Enviroment.Exit(1);
  7.   }
  8. }
I can see its not near your examples, but this is working.
I had gotten an error when I added "GeneralData gd = new GeneralData();"... Something about not needing to do with with static members or something. After I removed that code. I put in the GeneralData.GetMe() and it started working...

lol! I don't know why but hey. =D
Oct 23 '09 #13
Samishii23
246 100+
Expand|Select|Wrap|Line Numbers
  1. Namespace.Class Temp = new Namespace.Class();
This basic, instance caller ( the term evades my mind at this moment ) ?, is working. I can see all the variables in the dropdown, and theres no compiler errors.
Oct 23 '09 #14
GaryTexmo
1,501 Expert 1GB
Well, for the above, the reason you got the error is because you were trying to instantiate a static class. You don't need to instantiate a class to access its static methods/members. The reason it works now is because you added a non-static method, which then calls static methods.

So if you instantiated a new object, you couldn't access the static method you made, "GetMe" without an error, which in my compiler comes out to be "Static member 'ConsoleApplication1.MyConstants.GetItem(string)' cannot be accessed with an instance reference; qualify it with a type name instead." Which means exactly what it says, access it with the type name (whatever you called your class).

The example I posted above is what I tested with. The only change is where I wrote:

Expand|Select|Wrap|Line Numbers
  1.      switch (description.ToLower())
  2.      {
  3.        case "name":
  4.          obj = this.Name;
  5.          break;
  6.      }
Should actually be:
Expand|Select|Wrap|Line Numbers
  1.      switch (description.ToLower())
  2.      {
  3.        case "name":
  4.          obj = Constants.Name;
  5.          break;
  6.      }
Anyway, you may still want to pick whether or not you want a static class or a non-static class. Then again, you've got something that works (hopefully it makes sense why it works now :D) so you may just want to go on to other things. Though for the sake of clarity, you might want to revisit this at a later time.

I hope that helps :)
Oct 26 '09 #15
Samishii23
246 100+
I'm slightly glad I didn't put all my eggs in one library. lol.
So far, I have a BG thats 160k image, and 10 icons that are 8-12k in size each.
My compiled .exe is 12k. My Library compiled is 268k.
Yet when I run the program, the memory used is 16.8 MB.

When I load up around 1 MB of images into seperate Lists, the memory usage goes up to 28.4 MB used. Lol.

So glad I didn't put the images into a Library now.
Oct 29 '09 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: David Winter | last post by:
(Sorry - couldn't find a generic DocBook NG - I hope this is close enough.) I'm considering moving my documentation and translation business - which is currently done in proprietary formats such...
2
by: Fabian | last post by:
This javascript is meant for learning language vocabulary, specifically colours on this example. However, when I use images in the mtWord array, it breaks when checking for correct answers. It...
19
by: George Ziniewicz | last post by:
.. I try to use CSS when possible, though I am still learning and don't maximize its use. In particular, I still use a table to provide for a centered image in a few slideshows (though table...
7
by: Gumby | last post by:
I want to make a two-d array of unsigned ints that I can change the size of as I need more memory. To do this I put in the h file a simple pointer to the memory and row/col variables to retain the...
3
by: Wade | last post by:
08242005 1416 GMT-5 Recently some of you helped me with a script to change images. Well I was asked to make a change to the script and not knowing if what the school system is even possible, Ill...
5
by: jeremy.d.brewer | last post by:
Hi, I'm rather new to Python, and I've just written my first Python C module. I was wondering if some more experience Pythonista would look over what I've written and given me some pointers (or...
15
by: copx | last post by:
Q1: If an array is declared static in file A is it still valid to access it from file B? I mean if a function form file A which returns a pointer to a position inside of the array is called from...
10
by: Neo Geshel | last post by:
I am seeking to hand-roll my own blog in ASP.NET 2.0 and SQLExpress 2005. Why? Because I can. Because I will gain experience. The one thing that has me stumped at square one is inline images....
6
by: Robert Bravery | last post by:
Hi all, Can some one show me how to achieve a cross product of arrays. So that if I had two arrays (could be any number) with three elements in each (once again could be any number) I would get:...
1
by: Stephen.Schoenberger | last post by:
I am working with some images as byte arrays and am not sure nor can I figure out if as I am reading the image and saving smaller sub- images I am reading across and down the image or down and back...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.