Solved

Save a Picturebox Image to a .bmp file in vb.net.  SavePicture is not available

Posted on 2006-06-28
7
16,242 Views
Last Modified: 2013-12-25
I have a form that contains a picturebox that I've loaded up with an image and added the ability to freehand draw (Pen, Drawpath) in the picturebox.  I used to be able to leverage the SavePicture function to save that image to file but now am unable to find a solution in vb.net.

Thanks in advance.
0
Comment
Question by:kait14006
  • 3
  • 3
7 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 17003024
try a function like:

Public Function saveImageByPic(ByVal pic As PictureBox, ByVal sNewFile As String, ByVal saveFormat As System.Drawing.Imaging.ImageFormat) As Boolean
        Dim bAns As Boolean
        Dim saveExt As String
        Try
            pic.Image.Save(sNewFile, saveFormat)
            bAns = True 'return true on success
        Catch
            bAns = False 'return false on error
        End Try
        Return bAns
    End Function
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 17003034
try to explore the picturebox.Image.Save method.
0
 

Author Comment

by:kait14006
ID: 17006320
Thanks for the quick response.

Actually, I've already tried that.  It generates a file of an image before I painted on it.  I need it to generate a file that contains the image w/ the doodle.

Here's the snippet I used to doodle.
Private Sub pbtest_Paint((ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pbtest.Paint

Dim CurrentPen = New Pen(Color.FromArgb(myAlpha, strPencilColor), strPencilWidth) 'Set up the pen
            e.Graphics.DrawPath(CurrentPen, MousePath_EyeOutline)  'draw the path! :)

Any other ideas?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 49

Expert Comment

by:Ryan Chong
ID: 17006701
>>I need it to generate a file that contains the image
what's the "file" you mentioned here that you want to be generated?
0
 

Author Comment

by:kait14006
ID: 17007146
sorry, i should have clarified..

When i use the following, it saves a copy of the original image to the destination strFileName.  What I need is to save a copy of the image including my doodle.

pbtest.Image.Save(strFileName & ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
0
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 125 total points
ID: 17007387
You can try something like the below (VB2005) but I'm not sure if it's the best approach.


        Dim bmp As New Drawing.Bitmap(PictureBox1.Image.Width, PictureBox1.Image.Height)
        PictureBox1.DrawToBitmap(bmp, New Rectangle(0, 0, bmp.Width, bmp.Height))
        bmp.Save("c:\test.bmp")
0
 

Author Comment

by:kait14006
ID: 17010444
Thanks,

I think DrawToBitmap that works..
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…

706 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

18 Experts available now in Live!

Get 1:1 Help Now