Solved

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

Posted on 2006-06-28
7
16,301 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 51

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 51

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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 51

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

856 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