Solved

want to copy image from picturebox to imagebox

Posted on 2001-07-31
15
653 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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 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

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!

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

689 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