[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

want to copy image from picturebox to imagebox

Posted on 2001-07-31
15
Medium Priority
?
685 Views
Last Modified: 2007-12-19
Hello
i am drawing on the picturebox and as i can draw on picture box i want to copy the drawn image from picture box to imagebox
as picturebox cant be transparent i am using the imagebox,but as using imagebox i cant  draw on the picture how is it posible to copy the drawn image from picture box to imagebox or is it possible to make picture box transparent or is it possible to draw on imagebox
0
Comment
Question by:ajaybhalekar
  • 6
  • 3
  • 2
  • +3
15 Comments
 
LVL 4

Expert Comment

by:VincentLawlor
ID: 6337175
Image1.Picture = Picture1.Picture ?

Vin.
0
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6337207
SavePicture Statement Example
This example uses the SavePicture statement to save a graphic drawn into a Form object?s Picture property. To try this example, paste the code into the Declarations section of a Form object, and then run the example and click the Form object.

Private Sub Form_Click ()
   ' Declare variables.
   Dim CX, CY, Limit, Radius   as Integer, Msg as String
   ScaleMode = vbPixels   ' Set scale to pixels.
   AutoRedraw = True ' Turn on AutoRedraw.
   Width = Height   ' Change width to match height.
   CX = ScaleWidth / 2   ' Set X position.
   CY = ScaleHeight / 2   ' Set Y position.
   Limit = CX   ' Limit size of circles.
   For Radius = 0 To Limit   ' Set radius.
      Circle (CX, CY), Radius, RGB(Rnd * 255, Rnd * 255, Rnd * 255)
      DoEvents   ' Yield for other processing.
   Next Radius
   Msg = "Choose OK to save the graphics from this form "
   Msg = Msg & "to a bitmap file."
   MsgBox Msg
   SavePicture Image, "TEST.BMP"   ' Save picture to file.
End Sub

Hope this helps
WoK
0
 
LVL 4

Expert Comment

by:VincentLawlor
ID: 6337208
Try this.

When you are drawing on your picture box call the following.

Image1.Picture = Picture1.Image
Image1.Refresh

Vin.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6337225
Here is the final code:


Private Sub Image1_Click()
  Set Image1.Picture = LoadPicture("C:\TEST.BMP")
End Sub

Private Sub Picture1_Click()
  Dim CX, CY, Limit, Radius   As Integer, Msg As String
  Picture1.ScaleMode = vbPixels   ' Set scale to pixels.
  Picture1.AutoRedraw = True ' Turn on AutoRedraw.
  Picture1.Width = Picture1.Height
  CX = Picture1.ScaleWidth / 2   ' Set X position.
  CY = Picture1.ScaleHeight / 2   ' Set Y position.
  Limit = CX   ' Limit size of circles.
  For Radius = 0 To Limit   ' Set radius.
     Picture1.Circle (CX, CY), _
     Radius, RGB(Rnd * 255, Rnd * 255, Rnd * 255)
     DoEvents   ' Yield for other processing.
  Next Radius
  SavePicture Image, "C:\TEST.BMP"
End Sub

Good coding
WoK ;o)
0
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6337228
Private Sub Image1_Click()
  'Set Image1.Picture = LoadPicture("C:\TEST.BMP")
   Image1.Picture = Picture1.Image
   Image1.Refresh
End Sub

Will work too ...
WoK
0
 
LVL 4

Expert Comment

by:VincentLawlor
ID: 6337231
WoK>>
Think I suggested that already.

Vin.
0
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6337244
Private Sub Image1_Click()
  'Set Image1.Picture = LoadPicture("C:\TEST.BMP")
   Image1.Picture = Picture1.Image
   Image1.Refresh
End Sub

Will work too ...
WoK
0
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6337246
Yes, sorry but this will help ajaybhalekar
...
;o)
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6338051
maybe....

dim pic as stdpicture

'and when you are finish drawing on picturebox
set pic=picture1.picture
set image1.picture=pic
0
 
LVL 28

Accepted Solution

by:
Ark earned 300 total points
ID: 6339211
Hi
Private Declare Function TransparentBlt Lib "msimg32.dll"  (ByVal hdcDest As Long, ByVal nXOriginDest As Long, ByVal nYOriginDest As Long, ByVal nWidthDest As Long, ByVal nHeightDest As Long, ByVal hdcSrc As Long, ByVal nXOriginSrc As Long, ByVal nYOriginSrc As Long, ByVal nWidthSrc As Long, ByVal nHeightSrc As Long, ByVal crTransparent As Long) As Long

Private Sub cmdTransparent_Click()
  Dim clr As Long, w As Long, h As Long
  w = Picture1.ScaleWidth
  h = Picture1.ScaleHeight
  clr = Picture1.Point(0, 0)
  Call TransparentBlt(Picture2.hdc, 0, 0, w, h, Picture1.hdc, 0, 0, w, h, clr)
  Picture2.Refresh
End Sub

For more samples on how to use msimg32.dll take a look on my code at http://www.freevbcode.com/ShowCode.Asp?ID=1501

Cheers
0
 

Expert Comment

by:Mikesun
ID: 6341938
TransperantBlt in image32.dll :-)
0
 

Expert Comment

by:Mikesun
ID: 6341942
TransperantBlt() image32.dll :-))
0
 
LVL 28

Expert Comment

by:Ark
ID: 6342664
Great answer, Mikesun.
Did you look at code EXACTLY above your "answer"?

Cheers
0
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6344067
BLAMABLE Mikesun!
0
 

Expert Comment

by:costello
ID: 6396805
Rejecting MikeSun's answer.

Mikesun, please read the guidelines for 'Comments and Answers' http://www.experts-exchange.com/admin/adminShow.jsp?qid=20160770#tip

costello
Community Support Moderator @ eE
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question