Image.Save problem

C

Corobori

I am getting an error message "Description: Value cannot be null.
Parameter name: encoder" when performing this instruction:
frmPicView.pic.Image.Save(ms, frmPicView.pic.Image.RawFormat)

Here is the code: what I am doing is scanning a document and try to
get it from the form where I am previewing it directly to the database

Private Sub PicTwainPro1_PostScandotNet(ByVal classPtr As Integer,
ByVal objID As Integer, ByVal Cancel As Boolean) Handles
PicTwainPro1.PostScandotNet

Const sFName As String = "PicTwainPro1_PostScandotNet"
Try
'PicTwainPro1.IResX = 304
'Me.pic1.Image = PicTwainPro1.Picture
Dim frmPicView As New frmPicView
frmPicView.Width = PicTwainPro1.IWidth
frmPicView.Height = PicTwainPro1.IHeight
frmPicView.pic.Width = PicTwainPro1.IWidth
frmPicView.pic.Height = PicTwainPro1.IHeight
frmPicView.Show()
frmPicView.pic.Image = PicTwainPro1.Picture
Application.DoEvents()
Cancel = False
PicTwainPro1.CloseSession()

Dim ms As New MemoryStream
frmPicView.pic.Image.Save(ms,
frmPicView.pic.Image.RawFormat) ' <-- Having the error here

Dim arrayImage() As Byte = ms.GetBuffer
ms.Close() ' Closes the Memory Stream

Dim m_DAL As dbHandler

If m_DAL Is Nothing Then
m_DAL = New dbHandler
End If

m_DAL.InsertLBAImage(IDRacines, IDLBABanque, arrayImage)

m_DAL = Nothing

Catch ex As Exception
MessageBox.Show(sFName + ": " + ex.Message, Me.Text,
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
 
K

Ken Tucker [MVP]

Hi,

You are using the image.save(stream, imageformat).
frmPicView.pic.Image.RawFormat is not a valid imageformat. Try this.


Dim ms As New System.IO.MemoryStream

PictureBox1.Image.Save(ms, ImageFormat.Bmp)

Ken
---------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top