Copy ImageBox to PictureBox 
Author Message
 Copy ImageBox to PictureBox

Hi all...
Would anybody know how to transfer an ImageBox.Picture to a
PictureBox.Picture ???
Both are of arbitrary size.
I would like to have the PictureBox scaled so that the whole image is
seen.
Thanks
George


Sun, 09 May 2004 00:24:53 GMT  
 Copy ImageBox to PictureBox
You can certainly do that (even though it seems like a strange thing to want
to do!) but the method will depend on what it is, exactly, that you want to
achieve. For example, when you say that you "want the PictureBox scaled so
that the whole image is seen" do you mean that you want the Picture Box to
resize itself to the size of the picture, or do you want the picture to
resize itself to the size of the Picture Box? And, exactly how are you
determining the original size of the picture? As far as a bitmap or a
metafile or a Jpeg is concerned, there is no "real size" (although some of
those formats do contain "desired output size" data, which is in most cases
completely ignored by applications!). Bitmaps and Jpegs, for example, are
just "so many pixels wide by so many pixels high", and if you reproduce
exactly those original "picture pixels" on any kind of device then the
resultant size of the image will depend on the physical size of the pixels
on that device. It is just the same as though you had taken a snapshot with
a standard camera on a frame of a roll of film. The frame contains the
picture data, but it does not contain anything regarding the "picture size".
Take it to a developer and printer and they will produce whatever size
prints you require. Bitmaps and Jpegs, in this respect, are exactly the
same. Tell us what it is, exactly, that you are trying to do and it we will
be able to help you. Even Mr. Edward G. Nilges might post an answer for you,
although I doubt it, and even if he does I doubt that it will be of much
help to you!

Mike


Quote:
> Hi all...
> Would anybody know how to transfer an ImageBox.Picture to a
> PictureBox.Picture ???
> Both are of arbitrary size.
> I would like to have the PictureBox scaled so that the whole image is
> seen.
> Thanks
> George



Sun, 09 May 2004 01:14:50 GMT  
 Copy ImageBox to PictureBox
Perhaps this will be of some help . . . it is from a post I did a little while ago. Note
that the subroutine will work correctly no matter what the ImageBox container is. (So,
instead of using a PictureBox, you could use the Form itself if desired.)

Rick

You will need to put your picture into an ImageBox and place that ImageBox into a
PictureBox. Then give the following Subroutine a try. It properly fits the ImageBox (with
its Stretch property set to False) into its container (in this case, a PictureBox, but it
would also work if the container was a Frame, the Form, or anything else that can serve as
a container). So, for your program, use a PictureBox of whatever size you need as a
container for the ImageBox. (Make sure the ImageBox is *really* contained in the
PictureBox and not simply resting on top of it; cut it from the Form, click on the
PictureBox and paste it back into the now highlighted PictureBox.)

The first parameter is the name you have given to the ImageBox. The optional 2nd argument
allows you to specify a minimum number of pixel that the image must be away from the
closest edge of its container. As an example, you could call the following subroutine like
this

  Image1.Picture = LoadPicture("c:\windows\clouds.bmp")
  SetImageBoxSize Image1, 150

where your ImageBox is named Image1 and the picture won't come any closer than 150 twips
to an edge of its Container. Simply assign your picture to the ImageBox control and call
this subroutine.

Private Sub SetImageBoxSize(ImageBox As Image, _
            Optional ImageReductionAmount As Long = 0)
  Dim ParentRatio As Single
  Dim PictureRatio As Single
  Dim ContainerWidth As Single
  Dim ContainerHeight As Single
  Dim ContainerControl As Control
  With ImageBox
    .Visible = False
    PictureRatio = .Width / .Height
    On Error Resume Next
    ContainerWidth = .Container.ScaleWidth
    If Err.Number Then
      ContainerWidth = .Container.Width
      ContainerHeight = .Container.Height
    Else
      ContainerHeight = .Container.ScaleHeight
    End If
    ParentRatio = ContainerWidth / ContainerHeight
    If ParentRatio < PictureRatio Then
      .Width = ContainerWidth - 2 * ImageReductionAmount
      .Height = .Width / PictureRatio
    Else
      .Height = ContainerHeight - 2 * ImageReductionAmount
      .Width = .Height * PictureRatio
    End If
    .Stretch = True
    .Move (ContainerWidth - .Width) \ 2, _
               (ContainerHeight - .Height) \ 2
    .Visible = True
  End With
End Sub


Quote:
> Hi all...
> Would anybody know how to transfer an ImageBox.Picture to a
> PictureBox.Picture ???
> Both are of arbitrary size.
> I would like to have the PictureBox scaled so that the whole image is
> seen.
> Thanks
> George

______________________________________________________________________________
Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net


Sun, 09 May 2004 02:02:50 GMT  
 Copy ImageBox to PictureBox


Quote:
>Would anybody know how to transfer an ImageBox.Picture to a
>PictureBox.Picture ???
>Both are of arbitrary size.
>I would like to have the PictureBox scaled so that the whole image is
>seen.

To answer your question as stated:

Picture1.AutoResize = true
Set Picture1.Picture = Image1.Picture

--
Richard Mason



Sun, 09 May 2004 03:03:57 GMT  
 Copy ImageBox to PictureBox

Quote:
> You can certainly do that (even though it seems like a strange thing to want
> to do!) but the method will depend on what it is, exactly, that you want to
> achieve. For example, when you say that you "want the PictureBox scaled so
> that the whole image is seen" do you mean that you want the Picture Box to
> resize itself to the size of the picture, or do you want the picture to
> resize itself to the size of the Picture Box? And, exactly how are you
> determining the original size of the picture? As far as a bitmap or a
> metafile or a Jpeg is concerned, there is no "real size" (although some of
> those formats do contain "desired output size" data, which is in most cases
> completely ignored by applications!). Bitmaps and Jpegs, for example, are
> just "so many pixels wide by so many pixels high", and if you reproduce
> exactly those original "picture pixels" on any kind of device then the
> resultant size of the image will depend on the physical size of the pixels
> on that device. It is just the same as though you had taken a snapshot with
> a standard camera on a frame of a roll of film. The frame contains the
> picture data, but it does not contain anything regarding the "picture size".
> Take it to a developer and printer and they will produce whatever size
> prints you require. Bitmaps and Jpegs, in this respect, are exactly the
> same. Tell us what it is, exactly, that you are trying to do and it we will
> be able to help you. Even Mr. Edward G. Nilges might post an answer for you,
> although I doubt it, and even if he does I doubt that it will be of much
> help to you!

Is it just me, or does "What the?" apply to all the above?  :)


Sun, 09 May 2004 04:48:42 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Detecting and changing color of the gif file in picturebox or imagebox

2. ImageBox or PictureBox

3. Transparent imageboxes or pictureboxes?

4. putting a imagebox picture on a picturebox in the stretch mode

5. imagebox/picturebox error...

6. Rotate objekts like imageboxes and pictureboxes

7. how to scale picture in PictureBox or ImageBox

8. Annoying Imagebox/Picturebox thing!!

9. IMAGEbox dropped onto another imagebox flakey

10. copying a modified picturebox into a new picturebox

11. Copy picturebox to another picturebox

12. copying offscreen picturebox to another picturebox

 

 
Powered by phpBB® Forum Software