Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 8th, 2015, 07:40 PM
Friend of Wrox
Points: 1,035, Level: 12
Points: 1,035, Level: 12 Points: 1,035, Level: 12 Points: 1,035, Level: 12
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , USA.
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jmss66
Default Saving an image to a file from a PictureBox

I am reading a table off an Access database and displaying an image from one of its field to a picture box. I am able to display the image but when I try to save it to a file in a jpeg format, I am getting an error when it hits the line where the code saves the image to a file. I tried a couple of ways to assign a filename but I still get the error message below.

" A generic error occurred in GDI+"

Here is my code below
Code:
 
PrivateSub btnReader_Click(sender AsObject, e AsEventArgs) Handles btnReader.Click
Dim AccessConnection As OleDb.OleDbConnection
'Dim drTemplate As DataRow
Dim tblTemplate AsNewDataTable
Dim daTemplate AsNew OleDb.OleDbDataAdapter
Dim AccessCommand AsNew OleDb.OleDbCommand
Dim builder AsNew OleDb.OleDbCommandBuilder
Dim sqlString AsString
Dim strPathFileName AsString
AccessConnection = New OleDb.OleDbConnection(MDBConnString)
AccessConnection.Open()

sqlString = "SELECT BLOB_1, IS_KEY, Text_1_25, Text_2_25 FROM ID_PRO WHERE IS_Key = '1'"
AccessCommand = New OleDb.OleDbCommand(sqlString, AccessConnection)
daTemplate = New OleDb.OleDbDataAdapter(AccessCommand)
builder = New OleDb.OleDbCommandBuilder(daTemplate)
daTemplate.MissingSchemaAction = MissingSchemaAction.AddWithKey
tblTemplate = NewDataTable
daTemplate.Fill(tblTemplate)

Dim RetVal AsLong
Dim FieldLen AsInt32
 
Dim AccessDataReader As OleDb.OleDbDataReader = AccessCommand.ExecuteReader()
AccessDataReader.Read()
FieldLen = AccessDataReader.Item(0).Length
Dim PictureByteArray(FieldLen - 1) AsByte
Dim startIndex AsInteger = 0
RetVal = AccessDataReader.GetBytes(0, startIndex, PictureByteArray, 0, PictureByteArray.Length)
Dim BLOBDataStream AsNew IO.MemoryStream(PictureByteArray)
Me.PictureBox1.Image = Image.FromStream(BLOBDataStream)
strPathFileName = "C:\OLEtoJPEG\Pictures\" & tblTemplate.Rows(0).Item("Text_1_25") & " " & tblTemplate.Rows(0).Item("Text_2_25") & ".jpg"
Me.PictureBox1.Image.Save("C:\OLEtoJPEG\Pictures\" & tblTemplate.Rows(0).Item("Text_2_25") & " " & tblTemplate.Rows(0).Item("Text_1_25") & ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
Me.PictureBox1.Image.Save("C:\Test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
 
AccessDataReader.Close()
AccessConnection.Close()
EndSub
Any help would be greatly appreciated.
Thanks
Reply With Quote
  #2 (permalink)  
Old October 21st, 2015, 02:18 AM
Authorized User
Points: 57, Level: 1
Points: 57, Level: 1 Points: 57, Level: 1 Points: 57, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 15
Thanks: 0
Thanked 1 Time in 1 Post
Default

make sure that the path exists and the logged in user account has write access to it. Easiest way is to try to create a test file in the destination folder from windows explorer.
__________________
Kushal Kaleshwari
Application Architect
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error while loading image to picturebox owen_xgy VS.NET 2002/2003 0 March 28th, 2008 09:49 AM
Show/ Hide image while saving file. arnabghosh Javascript How-To 7 June 26th, 2007 12:49 AM
Name of image in PictureBox purefan Beginning VB 6 5 November 27th, 2006 02:20 PM
Saving/Retrieving Image file to Database davekrunal46 VB How-To 6 January 11th, 2006 04:41 AM
VB6 - PictureBox and Image controls Ole Jensen Beginning VB 6 3 July 14th, 2005 05:49 PM



All times are GMT -4. The time now is 07:58 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.