Solved

want to copy image from picturebox to imagebox

Posted on 2001-07-31
15
620 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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 27

Accepted Solution

by:
Ark earned 100 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 27

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

777 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