How to copy a section of an image to the clipboard

Thread Solved

Join Date: Jun 2007
Posts: 20
Reputation: Rombosia is an unknown quantity at this point 
Solved Threads: 1
Rombosia Rombosia is offline Offline
Newbie Poster

How to copy a section of an image to the clipboard

 
0
  #1
Feb 4th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

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

 
0
  #2
Feb 5th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 509
Reputation: selvaganapathy is an unknown quantity at this point 
Solved Threads: 88
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro

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

 
1
  #3
Feb 7th, 2009
Hi,

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

Code
  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
KSG
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 20
Reputation: Rombosia is an unknown quantity at this point 
Solved Threads: 1
Rombosia Rombosia is offline Offline
Newbie Poster

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

 
0
  #4
Feb 7th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC