Solved

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

Posted on 2006-06-28
7
16,265 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

864 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

19 Experts available now in Live!

Get 1:1 Help Now