GdipGetImageThumbnail and pictureBox 
Author Message
 GdipGetImageThumbnail and pictureBox

Hi,

I am using the GDI+ function "GdipGetImageThumbnail" and a PictureBox
control to manipulate thumbnails. Is there a way to mantain unaltered
the content of the picturebox also when I refresh the control?

Thanks in advance, Nick
Home page: http://www.*-*-*.com/



Thu, 10 Feb 2005 04:35:46 GMT  
 GdipGetImageThumbnail and pictureBox


Quote:
>I am using the GDI+ function "GdipGetImageThumbnail" and a PictureBox
>control to manipulate thumbnails. Is there a way to mantain unaltered
>the content of the picturebox also when I refresh the control?

Before drawing you set picturebox.AutoRedraw = True
After drawing do Picturebox.Refresh

--
Richard Mason



Thu, 10 Feb 2005 12:16:30 GMT  
 GdipGetImageThumbnail and pictureBox
Thanks Richard,
but not work.
In addition, when I write to the control with HDC reference, I cannot
manipulate the content, I mean that I cannot use the .picture property
to manage the picture that I write inside the control...

On Sun, 25 Aug 2002 16:16:30 +1200, Richard Mason

Quote:



>>I am using the GDI+ function "GdipGetImageThumbnail" and a PictureBox
>>control to manipulate thumbnails. Is there a way to mantain unaltered
>>the content of the picturebox also when I refresh the control?

>Before drawing you set picturebox.AutoRedraw = True
>After drawing do Picturebox.Refresh

Home page: http://geocities.com/whisky1767


Thu, 10 Feb 2005 14:44:02 GMT  
 GdipGetImageThumbnail and pictureBox
If the image is initially drawn inside the picture box, try:
    PictureBox.Picture = PictureBox.Image
If you have VB5, you might also want to read Q174825.

Avery


Quote:
> Hi,

> I am using the GDI+ function "GdipGetImageThumbnail" and a PictureBox
> control to manipulate thumbnails. Is there a way to mantain unaltered
> the content of the picturebox also when I refresh the control?

> Thanks in advance, Nick
> Home page: http://geocities.com/whisky1767



Thu, 10 Feb 2005 16:10:39 GMT  
 GdipGetImageThumbnail and pictureBox
Thanks Avery,
but not work. It is as if the PictureBox is empty.
It's like to write in a part of the control where it is not possible
to read.
Any tips about?

Quote:

>If the image is initially drawn inside the picture box, try:
>    PictureBox.Picture = PictureBox.Image
>If you have VB5, you might also want to read Q174825.

>Avery



>> Hi,

>> I am using the GDI+ function "GdipGetImageThumbnail" and a PictureBox
>> control to manipulate thumbnails. Is there a way to mantain unaltered
>> the content of the picturebox also when I refresh the control?

>> Thanks in advance, Nick
>> Home page: http://geocities.com/whisky1767

Home page: http://geocities.com/whisky1767


Thu, 10 Feb 2005 17:14:24 GMT  
 GdipGetImageThumbnail and pictureBox
    Hmm, I think I had misunderstood. Let's see if I got it right this time:
You are successfully painting a picture in the picture box control, but
you'd like to alter the image later on down the road? So you created a
graphics object based on the PictureBox hDC and it no longer has the picture
there? Or you want the PictureBox picture property to hold the original
image? Is this correct?

    There are at least two options to assign a GDI+ image to a Picture
property. I shall now show you snippets for doing it in the two ways I know.
You can draw the GDI+ image on an object, such as a picture box and assign
the picturebox image property to the picture property, or you can assign the
GDI+ image directly to the picture property (which would probably be the
better way to go).
'---------------------------------------------------------------------------
-----
' Assign via drawing
'---------------------------------------------------------------------------
-----
   Dim graphics As Long, bitmap As Long
   Dim lngHeight As Long, lngWidth As Long

      ' You can turn this off after the picture property is set if you don't
want it on...
      picGrapes.AutoRedraw = True

      ' Load the image since we don't have one open
      Call GdipLoadImageFromFile(...., bitmap)

      ' Get the image height and width
      Call GdipGetImageHeight(bitmap, lngHeight)
      Call GdipGetImageWidth(bitmap, lngWidth)

      ' Assuming scaling is in pixels
      ' Update the picture box size
      picGrapes.Width = lngWidth
      picGrapes.Height = lngHeight

      ' Now create the graphics object
      Call GdipCreateFromHDC(picGrapes.hdc, graphics)

      ' Paint the image on the picture box
      Call GdipDrawImageRectI(graphics, bitmap, 0, 0, lngWidth, lngHeight)

      ' Cleanup
      Call GdipDisposeImage(bitmap)
      Call GdipDeleteGraphics(graphics)

      ' Save the picture
      picGrapes.Picture = picGrapes.image
'---------------------------------------------------------------------------
-----
NOTE: If the picturebox size is too small or too large when you do the
.Picture = .Image, the image will be cropped or have "blank" areas.

'---------------------------------------------------------------------------
-----
' Assign via HBITMAP
'---------------------------------------------------------------------------
-----
   Dim bitmap As Long, hBmp as Long

      ' Load the image since we don't have one open
      Call GdipLoadImageFromFile(...., bitmap)

      ' Get the HBITMAP handle
      Call GdipCreateHBITMAPFromBitmap(bitmap, hBmp, 0)

      ' Save the picture
      picGrapes.Picture = BitmapToPicture(hBmp)

      ' Cleanup
      Call GdipDisposeImage(bitmap)
'---------------------------------------------------------------------------
-----
   I went looking for a function that would do the conversion of HBITMAP to
Picture and here are a few select results ( keyword: BitmapToPicture ):

http://vbaccelerator.com/tips/vba0025.htm

http://www.vbcodemagician.dk/tips/gfx_vbpicfromgdibitmap.htm

    Now, what you need to do when you want to load and edit the image in the
picture box is to create an image based on the picture box's current image:

' Assumes that a picture is in the picture box
Call GdipCreateBitmapFromHBITMAP(picGrapes.Picture.Handle,
picGrapes.Picture.hpal, bitmap)

    Now you'll have the image loaded, but how to alter it? Well, you can
create a drawing area on a device context via hDC or create a graphics
object based on the loaded image like so:

  Call GdipGetImageGraphicsContext(bitmap, graphics)

    Now you can alter the image all you want either in memory or on a device
context or window. If drawing on a graphics object created from an image, be
advised that the drawable area is limited to the size of the bitmap, but you
could use GdipCreateBitmapFromGraphics or something to create a new blank,
compatible bitmap (larger or smaller as you need) to draw on if you wanted
to draw everything in memory. Now that you should be able to alter the
image, but how will the picture box know of the changes? You'll have to
create yet another graphics object based on the picture box's hDC and draw
the new image there, similar to the code snippets I previously mentioned.

REMEMBER: When you open a graphics object, try not to change anything that
would alter the drawing area while the graphics object is still active. This
is because GDI+ will not recognize the change - you should delete the active
graphics object and recreate it if you want to do something like that. In
that above picture assignment, I had been opening the graphics object and
then resizing the picture box which gave me an image the size of the initial
picture box and it took a while to figure out what was wrong!

'---------------------------------------------------------------------------
-----

    If my assumptions and theories (and therefore the above discussion) are
all totally off-track and not what you needed, then what exactly you are
trying to do? I fear it is still unclear to me. Otherwise, does all this
help any?

Avery



Fri, 11 Feb 2005 02:16:47 GMT  
 GdipGetImageThumbnail and pictureBox
    Oops! Seems I didn't free the created HBITMAP in the sample. The C++
GDI+ docs never said anything about needing to delete, but the .NET GDI+
docs say you must....good thing I double checked, but I should have gotten a
clue from the "Create" in GdipCreateHBITMAPFromBitmap. Oh well, you might
want to add this line in the cleanup of the HBITMAP picture assignment
example, preferrably before you dispose of the GDI+ image:

Note: Be sure to declare the DeleteObject API!
'-----------------------------------------
DeleteObject hBmp
'-----------------------------------------

Avery



Fri, 11 Feb 2005 04:51:24 GMT  
 GdipGetImageThumbnail and pictureBox
Sorry, I am a beginner to use GDI+ but after hours of hard work I have
successfully implemented the library.
It is astonishing to see the performance of the library!
From 5 sec to display a page of pictures by 1280x1024 to 1 sec!

Now I have correct my code and AutoRedraw work well, in addition I
have seen in internet some code to speed up this property...

Thank you very much for your help, Nick

Quote:

>    Hmm, I think I had misunderstood. Let's see if I got it right this time:
>You are successfully painting a picture in the picture box control, but
>you'd like to alter the image later on down the road? So you created a
>graphics object based on the PictureBox hDC and it no longer has the picture
>there? Or you want the PictureBox picture property to hold the original
>image? Is this correct?

>    There are at least two options to assign a GDI+ image to a Picture
>property. I shall now show you snippets for doing it in the two ways I know.
>You can draw the GDI+ image on an object, such as a picture box and assign
>the picturebox image property to the picture property, or you can assign the
>GDI+ image directly to the picture property (which would probably be the
>better way to go).
>'---------------------------------------------------------------------------
>-----
>' Assign via drawing
>'---------------------------------------------------------------------------
>-----
>   Dim graphics As Long, bitmap As Long
>   Dim lngHeight As Long, lngWidth As Long

>      ' You can turn this off after the picture property is set if you don't
>want it on...
>      picGrapes.AutoRedraw = True

>      ' Load the image since we don't have one open
>      Call GdipLoadImageFromFile(...., bitmap)

>      ' Get the image height and width
>      Call GdipGetImageHeight(bitmap, lngHeight)
>      Call GdipGetImageWidth(bitmap, lngWidth)

>      ' Assuming scaling is in pixels
>      ' Update the picture box size
>      picGrapes.Width = lngWidth
>      picGrapes.Height = lngHeight

>      ' Now create the graphics object
>      Call GdipCreateFromHDC(picGrapes.hdc, graphics)

>      ' Paint the image on the picture box
>      Call GdipDrawImageRectI(graphics, bitmap, 0, 0, lngWidth, lngHeight)

>      ' Cleanup
>      Call GdipDisposeImage(bitmap)
>      Call GdipDeleteGraphics(graphics)

>      ' Save the picture
>      picGrapes.Picture = picGrapes.image
>'---------------------------------------------------------------------------
>-----
>NOTE: If the picturebox size is too small or too large when you do the
>.Picture = .Image, the image will be cropped or have "blank" areas.

>'---------------------------------------------------------------------------
>-----
>' Assign via HBITMAP
>'---------------------------------------------------------------------------
>-----
>   Dim bitmap As Long, hBmp as Long

>      ' Load the image since we don't have one open
>      Call GdipLoadImageFromFile(...., bitmap)

>      ' Get the HBITMAP handle
>      Call GdipCreateHBITMAPFromBitmap(bitmap, hBmp, 0)

>      ' Save the picture
>      picGrapes.Picture = BitmapToPicture(hBmp)

>      ' Cleanup
>      Call GdipDisposeImage(bitmap)
>'---------------------------------------------------------------------------
>-----
>   I went looking for a function that would do the conversion of HBITMAP to
>Picture and here are a few select results ( keyword: BitmapToPicture ):

>http://vbaccelerator.com/tips/vba0025.htm

>http://www.vbcodemagician.dk/tips/gfx_vbpicfromgdibitmap.htm

>    Now, what you need to do when you want to load and edit the image in the
>picture box is to create an image based on the picture box's current image:

>' Assumes that a picture is in the picture box
>Call GdipCreateBitmapFromHBITMAP(picGrapes.Picture.Handle,
>picGrapes.Picture.hpal, bitmap)

>    Now you'll have the image loaded, but how to alter it? Well, you can
>create a drawing area on a device context via hDC or create a graphics
>object based on the loaded image like so:

>  Call GdipGetImageGraphicsContext(bitmap, graphics)

>    Now you can alter the image all you want either in memory or on a device
>context or window. If drawing on a graphics object created from an image, be
>advised that the drawable area is limited to the size of the bitmap, but you
>could use GdipCreateBitmapFromGraphics or something to create a new blank,
>compatible bitmap (larger or smaller as you need) to draw on if you wanted
>to draw everything in memory. Now that you should be able to alter the
>image, but how will the picture box know of the changes? You'll have to
>create yet another graphics object based on the picture box's hDC and draw
>the new image there, similar to the code snippets I previously mentioned.

>REMEMBER: When you open a graphics object, try not to change anything that
>would alter the drawing area while the graphics object is still active. This
>is because GDI+ will not recognize the change - you should delete the active
>graphics object and recreate it if you want to do something like that. In
>that above picture assignment, I had been opening the graphics object and
>then resizing the picture box which gave me an image the size of the initial
>picture box and it took a while to figure out what was wrong!

>'---------------------------------------------------------------------------
>-----

>    If my assumptions and theories (and therefore the above discussion) are
>all totally off-track and not what you needed, then what exactly you are
>trying to do? I fear it is still unclear to me. Otherwise, does all this
>help any?

>Avery

Home page: http://geocities.com/whisky1767


Fri, 11 Feb 2005 15:02:58 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. GDI+ GdipGetImageThumbnail question

2. Help!! Loading PictureBox FromStream and PictureBox.Image.Save

3. Best way to preview a font in a PictureBox (WAS: Question on Picturebox or an alternative)

4. copying a modified picturebox into a new picturebox

5. Copy picturebox to another picturebox

6. PictureBox inside PictureBox...

7. Best way to preview a font in a PictureBox (WAS: Question on Picturebox or an alternative)

8. copying offscreen picturebox to another picturebox

9. Best way to preview a font in a PictureBox (WAS: Question on Picturebox or an alternative)

10. GDI+ Load bitmap from PictureBox, skew bmp with graphics, back to PictureBox - How To?

11. How do I create a PictureBox within a PictureBox at run-time?

12. how can i send a picture (picturebox) from client via winsock or so to a pictureBox in server ???

 

 
Powered by phpBB® Forum Software