Solved

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

Posted on 2006-06-28
7
16,323 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: 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.

Question has a verified solution.

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

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 …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

763 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