Welcome to Dream.In.Code
Become a VB Expert!

Join 137,234 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,641 people online right now. Registration is fast and FREE... Join Now!




picturebox

 
Reply to this topicStart new topic

picturebox

eukim82
24 Feb, 2007 - 07:46 AM
Post #1

New D.I.C Head
*

Joined: 5 Feb, 2007
Posts: 7


My Contributions
How could i save my drawing on picture box?
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Picturebox
24 Feb, 2007 - 11:09 AM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,859



Thanked: 50 times
Dream Kudos: 550
My Contributions
QUOTE(eukim82 @ 24 Feb, 2007 - 08:46 AM) *

How could i save my drawing on picture box?


Assumptions: You wrote a program that drew a bunch of stuff in a pictureBox, and now you want to save that image?

How you go about this depends on what version of VB you are using. In VB6 there is the Picture property (the image property in vb6 refers to persistant graphics loaded), in .net the image property.

I am no .net expert but I belive this is the general way:
CODE
Sub SaveImage(ByVal pbImage As PictureBox, ByVal sFile As String)
    Dim bmp As New Bitmap(pbImage.Width, pbImage.Height)
    Dim g As Graphics = Graphics.FromImage(bmp)
    Dim peArgs As New PaintEventArgs(g, New Rectangle(Point.Empty, bmp.Size))
    Me.InvokePaint(pbImage, peArgs)
    Dim imageFormat As Imaging.ImageFormat
    imageFormat = Imaging.ImageFormat.Bmp
    bmp.Save(sFile, imageFormat)
    g.Dispose()
    bmp.Dispose()
    peArgs.Dispose()
End Sub


In VB6 you have to copy the .Image property to the .picture property

CODE
sub saveImage(pbImage As PictureBox, sFile as String)
    pbImage.Picture = pbImage.Image
    SavePicture pbImage.Picture, sFile
end sub


and I am not SURE about this, but I think i remeber that you file name must end in the extension you want... .bmp for bmp, .gif for gif etc.. not SURE on that one.

User is offlineProfile CardPM
+Quote Post

MiraKimura
RE: Picturebox
27 Sep, 2007 - 07:01 AM
Post #3

New D.I.C Head
*

Joined: 27 Sep, 2007
Posts: 3


My Contributions
these is in vb or vb.net? because i try to paste it on vb6 and it shows in red color [error]. what should i change?
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Picturebox
27 Sep, 2007 - 07:53 AM
Post #4

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 3,914



Thanked: 34 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
If you're calling the SUB like this:
CODE
saveImage(Picture1, "c:\abc.bmp")

VB6 isn't going to accept that.
Subroutines Calling Statements must be preceded with the Call Keyword.

CODE
Call saveImage(Picture1, "c:\abc.bmp")
This should work.

Keep in mind that the SavePicture() always writes a BMP file no matter which extension you provide as the second parameter.
User is offlineProfile CardPM
+Quote Post

MiraKimura
RE: Picturebox
28 Sep, 2007 - 04:15 AM
Post #5

New D.I.C Head
*

Joined: 27 Sep, 2007
Posts: 3


My Contributions
Sub SaveImage(ByVal pctCircuit As PictureBox, ByVal sFile As String)
Dim bmp As New Bitmap(pctCircuit.Width, pctCircuit.Height)
Dim g As Graphics = Graphics.FromImage(bmp)
Dim peArgs As New PaintEventArgs(g, New Rectangle(Point.Empty, bmp.Size))
Me.InvokePaint(pctCircuit, peArgs)

Dim ImageFormat As Imaging.ImageFormat
ImageFormat = Imaging.ImageFormat.bmp
bmp.Save(sFile, imageFormat)
g.Dispose()
bmp.Dispose()
peArgs.Dispose()

pctCircuit.Picture = pctCircuit.Image
sFile = dlgSavePic.FileName
SavePicture ppctCircuitbImage.Picture, sFile
End Sub

can u tell me what is wrong here? there are certain keywords that did not appear in the drop down list if i retyped them again..

the red colored sentences are the errors.

tq for entertaining my problem smile.gif

[sorry, i cant put those in code because then the html for red color wont work]

This post has been edited by MiraKimura: 28 Sep, 2007 - 04:16 AM
User is offlineProfile CardPM
+Quote Post

MiraKimura
RE: Picturebox
4 Oct, 2007 - 06:18 AM
Post #6

New D.I.C Head
*

Joined: 27 Sep, 2007
Posts: 3


My Contributions
excuse me.. should i call any other libraries? because Bitmap, Graphics, PaintEventArgs, Imaging and so on is not listed in the drop down menu of VB6 that suppose to be appeared when you type..

can someone answer me..? sad.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 04:02PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month