EFileTahi-A Posted May 1, 2005 Posted May 1, 2005 I have loaded some images into a Hashtable (myHashtable.add(["pic1"], Image.FromFile("path"))), the problem is that don't know how to use them once they are inside the Hashtable. I would like then to assign then to Image or Bitmap objects like: Bitmap picture = myHashtable["x"]; I tryed countless times the way I would assign them with no success... Any help trully apreciated... Also, is there a simplier way of loading images to memory (with key names support)? Quote
PWNettle Posted May 2, 2005 Posted May 2, 2005 Any help trully apreciated... Your thinking should work as long as you use the same type of object throughout (I'm not sure about the casting potential between Image and Bitmap objects - for ex, putting an Image object in the hashtable and then trying to cast it to a Bitmap object might not work). I also don't see why you'd put brackets around the key (myHashtable.add(["pic1"],...) since that doesn't even compile (maybe that's just the way you typed it here...). Hashtables store everything as type Object so you'll usually need to explicitly cast the contents when you want to use them. So, either do both as Bitmaps: myHashtable.Add("pic1", new Bitmap("path")); Bitmap picture = (Bitmap) myHashtable["pic1"]; Or as Image objects: myHashtable.Add("pic1", Image.FromFile("path")); Image myImage = (Image) myHashtable["pic1"]; PictureBox1.Image = myImage; (I tried the Image object variant above on a .jpg image and it worked fine...) Also' date=' is there a simplier way of loading images to memory (with key names support)?[/quote'] No idea off hand. The hashtable idea will work and I wouldn't worry about it unless memory and/or performance are absolutely critical. Good luck, Paul Quote
EFileTahi-A Posted May 3, 2005 Author Posted May 3, 2005 thank you very much.... yes, I was missing the damn "(image)" / "(bitmap")... It works perfectly now... Am creating an 2D map editor for some RPG am plannig to build, and yes, speed would be truly a needed as it gets a bit laggy when building a map with many tiles... For any curiosity about this project of mine, drop a line... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.