Results 1 to 4 of 4

Thread: [02/03] Loading an image at runtime to a control e.g. button

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982

    [02/03] Loading an image at runtime to a control e.g. button

    I want to load an image (.png) onto a button at runtime without using an imagelist.
    The reason I do not want to use an imagelist is because the image quality deteriorates (goes all pixely) when an imagelist is used.
    If I assign an image to a picturebox image property the image looks fine.


    Things I do when I am bored: DotNetable

  2. #2
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: [02/03] Loading an image at runtime to a control e.g. button

    You have two good options:
    1. Set the imagelist to the correct settings. By default, it resizes everything to 16x16.
    2. Use a resource file instead of an image list.(recommended because images can all be different sizes)

    You can assign them at run time from a file, but i don't recommend it.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982

    Re: [02/03] Loading an image at runtime to a control e.g. button

    Regarding point 1)
    The images are actually 16x16.
    If you set the transparent colour of the imagelist to white
    and set the image depth as 32bit the image then displays correctly when loaded into something with a white background, for example a listview item or picturebox.
    The image does not display properly on a button because the background of the button is not plain white.
    Hence the reason to load at runtime

    Regarding point 2)
    I have not tried that. I will have a hundred or so png files (16x16 images).
    I don't want to have large resource files.
    Maybe I'll have to try this to find out.


    Things I do when I am bored: DotNetable

  4. #4
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: [02/03] Loading an image at runtime to a control e.g. button

    evidently what you think is white isn't exactly white on your images. It should not render the color if it is set to transparent. Open the image in a program that you can view the color value of a pixel (such as photoshop) and verify that red,green, and blue values are all 255 (&Hff). If they aren't(and i am POSITIVE this is the issue) then you have two choices: use a floodfill in a graphics program to replace the off-white with white in every single image,
    or two: compute the correct value based on those three values (using the rgb function) and enter it as the transparency color in the listview. This is obviously much easier than the other method.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width