Retaining original Bitmap/GIF size in an imagelist

I have loaded several graphics into an imagelist. The dimensions of each graphic varies.
I have set imglist.imagesize to 120,120, but some of the graphics are 80,80  or 160,80 etc.
I use the imglist to load graphics into pictureboxes that are created at runtime. I wish to set the size of the picturebox based on the 'original' sizing of the graphic.
The problem appears to be that the dimensions are always 120,120.
Even if the item has physical dimensions of 80, 80 and I set the picturebox size to this, I get a 120,120 picture box.
I even tried setting the imglist.imagesize during runtime based on the physical dimensions to no avail

eg:

picBox.Size = New Size(imlRoom.Images(4).PhysicalDimension.Height, imlRoom.Images(4).PhysicalDimension.Width)
picBox.Image = imlRoom.Images(4)

How do I dimension and populate the picture box to show the original sizing. If there is another was beside imglist I am happy to go down another track, but the images need to be stored in the program. Thanks for any input.
Milkus1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

platinumbayCommented:
If you don't have too many images, you could add them as resources to the project.

Here is one example Google brought up:
http://www.vb-helper.com/howto_net_embedded_resources.html
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
Or if you don't have too many images and they are small, you can load them into invisible PictureBoxes.

~IM
0
Milkus1Author Commented:
I think I will go with Idle mind's idea, but the problem is that when i assign properties to my dynamically created controls I get problems
eg:
  picbox = pbItem1

the new control actually becomes the hidden picturebox. The hidden one is gone, therefore I can only use it once.
If I try

picbox.image = pbItem1.image
picbox.size = new size (pbitem1.height,pbItem1.width)

I get a blank picture box that is not scaled? Is there a way of cloning all properties of the 'hidden' picturebox to the new one, without losing it?
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Mike TomlinsonMiddle School Assistant TeacherCommented:
I didn't have any problems getting it to work:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim picbox As New PictureBox
        picbox.SizeMode = PictureBoxSizeMode.AutoSize
        picbox.Location = New Point(8, 40)
        picbox.Image = pbItem1.Image ' take image from hidden one
        Me.Controls.Add(picbox)
    End Sub

pbItem1 was my hidden PictureBox.

~IM
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bastawhizCommented:
I agree. The best way to do this is with Resources. Here is a pre-built function to get a stroed image from the project:

    Public Function GetResImage(ByVal Name As String) As Bitmap

        Dim im As System.IO.Stream = GetResStream(Name)
        'Dim nb As Bitmap = New Bitmap(im)

        Return New Bitmap(im)

    End Function

    Public Function GetResStream(ByVal Name As String) As IO.Stream

        'MsgBox(MScreen.NmSpc)

        Return System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(Application.ProductName & "." & Name)

    End Function


You would call this like:

Image1.Image = GetResImage("YourImageName.gif")

You will, however, have to set the Build Action on your embedded images to Embedded Resource.
0
Milkus1Author Commented:
I have tried IdleMind's suggestion, and I got it to work so I can add multiple controls which i can rotate. Thanks!
The issue is that the graphics seem very unstable, If I have a rotated picture (eg: 90' rotation) and then drag another picture box over it the picture reverts back to the initial view or the graphic may be half and half. If I minimize the screen all the graphics go back to the original setting.
Is the other way more stable.? Or does it come down to the rotation method -

pb.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
Hi Milkus1,

I'm not having any problems with rotated graphics in a picturebox as you describe.

Can you gave us a little more detail into what you are doing or supply some code?

~IM
0
Milkus1Author Commented:
Thanks for the response IdleMind.
I have figured out partly what was occurring, setting pbx to the sender seemed to cause the 'static' picturebox to rotate (the one it copied the original graphic from).
If I had rotated the figure 90', then created a new picturebox of the same graphic the dimension were reversed
I therefore tried the following code, having an intermediate picturebox that the 'rotated' image was taken from. This seemed to help. I also changed from autostretch to autosize when a new picturebox was created.

What I am left with is the graphic being proportional when a new one is created, but the rotation will mirror that of the last one made of that chosen graphic.
eg: If I make a pbx ^, rotate it >, then the next one I make is >. I would like it ^ (hope it makes sense)

The last issue is the stability of the graphics in a new pbx, if I drag a pbx1 over pbx2, then some of the time the graphic in pbx2 becomes distorted,rotates back to the original state, or is half and half.



Code for rotating

    Private Sub picBox_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        Dim pbx As PictureBox = CType(sender, PictureBox)

        If e.Button = MouseButtons.Left Then
            pbx.BringToFront()
            startPoint = pbx.PointToScreen(New Point(e.X, e.Y))
        Else
            picFlip.Image = pbx.Image

            If pbx.Width = pbx.Height Then
                picFlip.Image.RotateFlip(RotateFlipType.Rotate90FlipXY)
                pbx.Image = picFlip.Image
                pbx.Refresh()
            Else
                picFlip.Height = pbx.Width
                picFlip.Width = pbx.Height
                picFlip.Image.RotateFlip(RotateFlipType.Rotate90FlipXY)
                pbx.Height = picFlip.Height
                pbx.Width = picFlip.Width
                pbx.Image = picFlip.Image
                pbx.Refresh()
            End If
        End If

    End Sub

Code for new control..

    Private Sub AddNewFRNControl(ByVal psType As String, ByVal psTag As String)
        Dim picBox As New PictureBox

        picBox.SizeMode = PictureBoxSizeMode.AutoSize
        Select Case psType
            Case "FRN"
                Select Case miFurn
                    Case 1
                        picBox.Size = New Size(picFrnMPWIII.Height * miRatio \ 100, picFrnMPWIII.Width * miRatio \ 100)
                        picBox.Image = picFrnMPWIII.Image
                        picBox.AccessibleDescription = "MPWIII (1000 x 1000)"
                        ...........

                End Select
        End Select

'centre
        picBox.Location = New Point(picRoom.Width / 2 - 10, picRoom.Height / 2 - 10)
'tag for tooltip
        picBox.Tag = psTag
'add to container
        picRoom.Controls.Add(picBox)
        picBox.BringToFront()

        AddHandler picBox.MouseDown, AddressOf picBox_MouseDown
        AddHandler picBox.MouseUp, AddressOf picBox_MouseUp
        AddHandler picBox.MouseMove, AddressOf picBox_MouseMove
        AddHandler picBox.MouseHover, AddressOf picBox_MouseHover
   End Sub
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.