Solved

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

Posted on 2006-06-28
7
16,277 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 50

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 50

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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 50

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

809 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