Re: System.InvalidCastException for Bitmap Constructor -- Please help!!!!
From: Me (PocketPCgymarquez_at_sbcglobal.net)
Date: 03/14/04
- Next message: Justin Rogers: "Re: comparing images..."
- Previous message: Me: "Re: System.InvalidCastException for Bitmap Constructor -- Please help!!!!"
- In reply to: Me: "System.InvalidCastException for Bitmap Constructor -- Please help!!!!"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 14 Mar 2004 19:06:05 GMT
I solved the problems:
1. myBitmap = New Bitmap("myfile.bmp", True) was incorrect. I changed this
line to myBitmap = New Bitmap("myfile.bmp") which got rid of the error and
displayed the photo in my control. But that was only half the problem.
2. I changed "myfile.bmp" to myfile.jpeg. Obviously, it didn't make much
difference on the Desktop but it made a world of difference on the PDA.
Once I did that, I was able to create an image file on the desktop and open
it up in the PDA.
Gigi
"Me" <PocketPCgymarquez@sbcglobal.net> wrote in message
news:OxO4c.58234$hH1.2590@newssvr33.news.prodigy.com...
> 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
>
>
- Next message: Justin Rogers: "Re: comparing images..."
- Previous message: Me: "Re: System.InvalidCastException for Bitmap Constructor -- Please help!!!!"
- In reply to: Me: "System.InvalidCastException for Bitmap Constructor -- Please help!!!!"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|