943,907 Members | Top Members by Rank

Ad:
Feb 4th, 2009
0

How to copy a section of an image to the clipboard

Expand Post »
hi guys,
if I have a form with, say, a picturebox in it. The picturebox is loaded with an image, and I need to copy just a section of it, say at rectangular points, X, Y, L and W to the clipboard, or to another picturebox. Is it possible in VB6?
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Rombosia is offline Offline
21 posts
since Jun 2007
Feb 5th, 2009
0

Re: How to copy a section of an image to the clipboard

Yes... but it will require a noxious amount of API calls with GDI. I suppose a great start would be researching GetDC() api call, and then working on learning BitBlt. You could probably get the device context of your picturebox, then use bitblt to get only a certain area of the picture and copy it to a new picturebox (you may want StretchBlt instead of bitblt) and from there, you can use the standard clipboard methods (clipboard.setdata()), or you can get crazy, and use the Clipboard API Calls.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Feb 7th, 2009
1

Re: How to copy a section of an image to the clipboard

Hi,

You can also use PaintPicture () to get the portion of image

Code
VB Syntax (Toggle Plain Text)
  1. Option Explicit
  2. Dim iX As Integer, iY As Integer, iHeight As Integer, iWidth As Integer
  3.  
  4. Private Sub cmdCopy_Click()
  5. 'Set Destination Picture box width and Height
  6. picDest.Width = iWidth
  7. picDest.Height = iHeight
  8. 'Copy the Portion of picture from Source to Destination
  9. picDest.PaintPicture picSource.Picture, _
  10. 0, 0, iWidth, iHeight, _
  11. iX, iY, iWidth, iHeight
  12. 'Set drawn image to picture
  13. picDest.Picture = picDest.Image
  14. 'Copy to Clipboard
  15. Clipboard.SetData picDest.Picture
  16. End Sub
  17.  
  18. Private Sub Form_Load()
  19. 'Picture Dimension
  20. iX = 1000 ' in twips
  21. iY = 1000
  22. iHeight = 2000
  23. iWidth = 2000
  24. picDest.AutoRedraw = True
  25. End Sub
Reputation Points: 44
Solved Threads: 101
Posting Pro
selvaganapathy is offline Offline
547 posts
since Feb 2008
Feb 7th, 2009
0

Re: How to copy a section of an image to the clipboard

selvaganapathy, that did the magic!!! And Comatose, I had dug well into BitBlt. I'm sure it'll help me one of these fine Image days. Thanks guys.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Rombosia is offline Offline
21 posts
since Jun 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Seeking for this for so Long
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: excel as a database





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC