M
Me
Hello,
I am getting a System.InvalidCastException from this line of code : myBitmap
= New Bitmap("myfile.bmp", True).
I am working on a Win2K, .NET 2003, VB.NET environment. I am developing for
the .NET Compact Framework using an iPAQ 4350. In order to isoloate the
problem, I always run my code on .NET Framework Desktop system.
Below is the entire code listing. The code works perfectly on a .NET 2003
,Windows 2K Desktop PC. Running the identical code on a .NET 2003 Pocket PC
(iPAQ 4350) yields the System.InvalidCastException exception.
I have confirmed that the file is acutally created on the PDA.
I have noticed one other thing. When I run the code on the Desktop, the
bitmap image displays perfectly in the PictureBox. However, if I copy the
..bmp file that my code created on the Desktop to the PDA, I can open the
file, but nothing appears to be displayed.
Also Note that the original files is a JPEG which I convert to a bitmap.
Dim Response As WebResponse
Dim ResponseStream As Stream
Dim Request As WebRequest
Request = WebRequest.Create("http://www.images.com/picture.jpg")
Response = Request.GetResponse
ResponseStream = Response.GetResponseStream
Dim numBytesToRead As Integer = CInt(Response.ContentLength)
Dim bytes(Response.ContentLength) As Byte
Dim numBytesRead As Integer = 0
While numBytesToRead + 1 > 0
Dim n As Integer = ResponseStream.Read(bytes, numBytesRead,
numBytesToRead)
If n = 0 Then
Exit While
End If
numBytesRead += n
numBytesToRead -= n
End While
Dim b As Bitmap
b = New Bitmap(New MemoryStream(bytes))
Dim fs As New FileStream("myfile.bmp", FileMode.Create)
fs.Write(bytes, 0, bytes.Length)
fs.Close()
'Clean up before exiting.
Cursor.Current = Cursors.Default
Response.Close()
Dim myBitmap As Bitmap
'This error showed up on in the the following line of code (ONLY in
..NET CF).
'An unhandled exception of type 'System.InvalidCastException'
occurred in Microsoft.VisualBasic.dll
'Additional(Information) : InvalidCastException()
--> myBitmap = New Bitmap("myfile.bmp", True)
' The image loads nicely from the file, but only from .Net Framework,
NOT
..NET CF!
PictureBox1.Image = myBitmap
PictureBox1.Update()
Any input on what is going on, why, and how I might solve the problem?
Thanks,
Gigi
I am getting a System.InvalidCastException from this line of code : myBitmap
= New Bitmap("myfile.bmp", True).
I am working on a Win2K, .NET 2003, VB.NET environment. I am developing for
the .NET Compact Framework using an iPAQ 4350. In order to isoloate the
problem, I always run my code on .NET Framework Desktop system.
Below is the entire code listing. The code works perfectly on a .NET 2003
,Windows 2K Desktop PC. Running the identical code on a .NET 2003 Pocket PC
(iPAQ 4350) yields the System.InvalidCastException exception.
I have confirmed that the file is acutally created on the PDA.
I have noticed one other thing. When I run the code on the Desktop, the
bitmap image displays perfectly in the PictureBox. However, if I copy the
..bmp file that my code created on the Desktop to the PDA, I can open the
file, but nothing appears to be displayed.
Also Note that the original files is a JPEG which I convert to a bitmap.
Dim Response As WebResponse
Dim ResponseStream As Stream
Dim Request As WebRequest
Request = WebRequest.Create("http://www.images.com/picture.jpg")
Response = Request.GetResponse
ResponseStream = Response.GetResponseStream
Dim numBytesToRead As Integer = CInt(Response.ContentLength)
Dim bytes(Response.ContentLength) As Byte
Dim numBytesRead As Integer = 0
While numBytesToRead + 1 > 0
Dim n As Integer = ResponseStream.Read(bytes, numBytesRead,
numBytesToRead)
If n = 0 Then
Exit While
End If
numBytesRead += n
numBytesToRead -= n
End While
Dim b As Bitmap
b = New Bitmap(New MemoryStream(bytes))
Dim fs As New FileStream("myfile.bmp", FileMode.Create)
fs.Write(bytes, 0, bytes.Length)
fs.Close()
'Clean up before exiting.
Cursor.Current = Cursors.Default
Response.Close()
Dim myBitmap As Bitmap
'This error showed up on in the the following line of code (ONLY in
..NET CF).
'An unhandled exception of type 'System.InvalidCastException'
occurred in Microsoft.VisualBasic.dll
'Additional(Information) : InvalidCastException()
--> myBitmap = New Bitmap("myfile.bmp", True)
' The image loads nicely from the file, but only from .Net Framework,
NOT
..NET CF!
PictureBox1.Image = myBitmap
PictureBox1.Update()
Any input on what is going on, why, and how I might solve the problem?
Thanks,
Gigi