• Advertisement
Sign in to follow this  

[.net] Change ImageList Size at Runtime?

This topic is 3477 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

Is it possible to change an ImageList size at runtime? I want a user to be able to choose any arbitrary bitmap file and draw it in a tiled fashion onto a PictureBox of variable size (for a scrolling background), but it seems ImageList controls have a fixed size. I can't seem to figure out how this can be done with Windows Forms and GDI. Also, is there a way to check the bitmap image properties such as BPP after loading it into a Bitmap object? Oh also I am using C#, if it makes a difference. [Edited by - CandleJack on July 12, 2008 12:35:24 PM]

Share this post


Link to post
Share on other sites
Advertisement
They do have a basic size but it can be changed up to a maximum of 256 pixels.


Image temp = Bitmap.FromFile(@"c:\R106526A.jpg");
ImageList newImages = new ImageList();
int imageListWidth;
int imageListHeight;
if (temp.Width > 256 || temp.Height > 256)
{
float multiplier = 0.0f;
if (temp.Width >= temp.Height)
{
multiplier = 256.0f / temp.Width;
}
else
{
multiplier = 256.0f / temp.Height;
}
imageListWidth = (int)(temp.Width * multiplier + .5);
imageListHeight = (int)(temp.Height * multiplier + .5);

}
else
{
imageListWidth = temp.Width;
imageListHeight = temp.Height;
}

newImages.ImageSize = new Size(imageListWidth, imageListHeight);
newImages.Images.Add(temp);
this.listView1.LargeImageList = newImages;
this.listView1.BackgroundImage = this.listView1.LargeImageList.Images[0];
this.listView1.BackgroundImageTiled = true;




Hope that helps.
theTroll

Share this post


Link to post
Share on other sites
Thanks, this works good enough! I don't really want the image size to be shrunken, but I guess I can just impose that limitation that the selected bitmap must be less than 256x256 in dimension. One question though: I've never used the ListView control. I've been drawing all my graphics into a PictureBox. Is the ListView a better solution? I looked it up on MSDN, though I'm still not quite sure about what exactly it does. I'm rendering my tile images, as well as other non-bitmap file graphics (Using methods like DrawLine()) such as a Selection object to highlight selected tiles, lines for a grid, and a custom mouse cursor. Can it do this as well?

Share this post


Link to post
Share on other sites
Didn't know what control you were using so I just used the ListView because it has an image list.

I would need to know more about what you are doing to give you better advice. The listview does not do what you are trying to do, but there are better controls I believe for what you are doing.

theTroll

Share this post


Link to post
Share on other sites
Ah I see. Well I am writing a 2D map editor. For the most part what I've been doing has been fairly straightforward and working as I need it, though I've noticed a little bit of slowdown when I try to use alpha blending for a transparent selection object. I know GDI is slow but this didn't bother me too much though. If you really think there are better ways though I am of course open to suggestions. If you want to see it in action, it is in a semi-working state and I can upload it to my website, along with some sample tile graphics that I made.

http://www.technodementia.com/Release/MapEditor.zip

The toolbar buttons are -

First Button - New Map
Second Button - Add Tile
Third Button - Add Object (Not yet working)
Fourth Button - Enable Tile Draw/Erase Mode
Fifth Button - Enable Tile Selection Mode


In draw mode, left click draws a tile, right click erases. In selection left click and drag selects.

Mouse wheel cycles through tiles in the library.

Also, holding the shift key down is a quick way to switch modes.

I think that's all the important stuff.

[Edited by - CandleJack on July 12, 2008 3:28:57 PM]

Share this post


Link to post
Share on other sites
Is the Scrollable list on the left designed to hold your tiles that you will draw with?

Is the large black area your map? Is that were you want the tiles?

theTroll

Share this post


Link to post
Share on other sites
Yep! When you push the new map button, it will create a grid of size 100x100 tiles (hard coded for now but will soon be user entered). You can then add tiles and start placing them into the grid.

Share this post


Link to post
Share on other sites
Ok, need to run to the store, I will have some "suggestions" when I get back.

theTroll

Share this post


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

  • Advertisement