Solved

want to copy image from picturebox to imagebox

Posted on 2001-07-31
15
605 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
Comment Utility
Image1.Picture = Picture1.Picture ?

Vin.
0
 
LVL 4

Expert Comment

by:WolfgangKoenig
Comment Utility
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
Comment Utility
Try this.

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

Image1.Picture = Picture1.Image
Image1.Refresh

Vin.
0
 
LVL 4

Expert Comment

by:WolfgangKoenig
Comment Utility
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
Comment Utility
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
Comment Utility
WoK>>
Think I suggested that already.

Vin.
0
 
LVL 4

Expert Comment

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

Will work too ...
WoK
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 4

Expert Comment

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

Expert Comment

by:Richie_Simonetti
Comment Utility
maybe....

dim pic as stdpicture

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

Accepted Solution

by:
Ark earned 100 total points
Comment Utility
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
Comment Utility
TransperantBlt in image32.dll :-)
0
 

Expert Comment

by:Mikesun
Comment Utility
TransperantBlt() image32.dll :-))
0
 
LVL 27

Expert Comment

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

Cheers
0
 
LVL 4

Expert Comment

by:WolfgangKoenig
Comment Utility
BLAMABLE Mikesun!
0
 

Expert Comment

by:costello
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now