Home All Groups Group Topic Archive Search About

Draggin and dropping image from word/excel - Getting the image width and height

Author
21 Sep 2005 10:41 PM
dug
Hi all

Im dragging and dropping an image from excel into a picturebox.
Unfortunately the picturebox rescales the image to the size of the
image box. Is there a way for me to retrieve the dragged image width
and height before it is resized and therefore resize it back?

Thanks

Author
22 Sep 2005 1:27 AM
MikeD
"dug" <elad.se***@gmail.com> wrote in message
news:1127342508.864784.100880@g14g2000cwa.googlegroups.com...
> Hi all
>
> Im dragging and dropping an image from excel into a picturebox.
> Unfortunately the picturebox rescales the image to the size of the
> image box. Is there a way for me to retrieve the dragged image width
> and height before it is resized and therefore resize it back?


You might consider using an Image control instead of a PictureBox.  You can
set the Image control's Stretch property to False and the control will
resize to fit the graphic.

--
Mike
Microsoft MVP Visual Basic
Author
22 Sep 2005 8:32 PM
dug
Thanks for that, that did the trick. However when I save the image it
is still enlarged (streched) is there a way to save it with its current
dimensions?

Thanks
Author
22 Sep 2005 9:42 PM
Mike Williams
"dug" <elad.se***@gmail.com> wrote in message
news:1127421139.134714.96410@g44g2000cwa.googlegroups.com...

> Thanks for that, that did the trick. However when I save the
> image it is still enlarged (streched) is there a way to save it
> with its current dimensions?

I've never been into this drag and drop stuff. I'm an old fashioned bugger
myself, really. Are you saying that you are dragging an image (that
apparently happens to be currently displayed at a specific small size in one
application) into a Picture Box in your VB application? If so, where does
the actual picture end up? For example, can you get at it as the Picture
property of the Picture Box that you are dragging it into? You have to
realise that all pictures (the original picture files, bmp, jpg or whatever)
have a specific pixel size, which is often nothing at all like the "visible
size" of the picture as it appears in a control or whatever. If you want to
save a picture to disk at a smaller pixel size than its original pixel size
then you need to resize it. One way to do so (if your machine is running at
a decent and preferably full colour depth) is to draw it at the new desired
size into a suitable device context (an autoredraw picture box, for example)
using either the VB PaintPicture method or the API StretchBlt (using an
appropriate stretchmode in the case of StretchBlt). Then you can save the
resultant smaller pixel size image (the Image property of the picture box)
as a bitmap using the VB SavePicture method (or, alternatively, you can save
the small bitmap as a jpg using either an enormous amount of code which
would be very difficult to write or, much easier, using the freely available
Intel jpeg library). Can you tell us exactly what you are doing.

Mike