PictureBox - Loading/Viewing JPG files

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have some code that loads JPG files into a PictureBox control. It works fine if the file is small, but files over 100K cause an Argument Exception error.

Since the compact frame work does not have:
picbox.image.fromfile("...")

I had to do it this way:
Dim MyImage As Bitmap
MyImage = New Bitmap(OpenFileDialog.FileName)
picbox.Image = CType(MyImage, Image)

It fails on New Bitmap(). I’ve seen other message threads about these bit map size problem, but no solution.

How can I view these larger files on my hand held? IE seems to handle it.

Thanks.
 
Large *.jpg files seem to load fine for me (PPC 2002 w/ SP2). I have been
successful opening a jpg that was approximately 340 KB. The code below works
for me:

If (Me.OpenFileDialog1.ShowDialog() = DialogResult.OK) Then
Me.PictureBox1.Image = New Bitmap(Me.OpenFileDialog1.FileName)
End If

Have you tried setting the large jpg as the PictureBox Image through the
VS.Net 2003 designer? Does this cause the same exception?

--
Tim Wilson
..Net Compact Framework MVP

Kurtis said:
I have some code that loads JPG files into a PictureBox control. It works
fine if the file is small, but files over 100K cause an Argument Exception
error.
Since the compact frame work does not have:
picbox.image.fromfile("...")

I had to do it this way:
Dim MyImage As Bitmap
MyImage = New Bitmap(OpenFileDialog.FileName)
picbox.Image = CType(MyImage, Image)

It fails on New Bitmap(). I've seen other message threads about these bit
map size problem, but no solution.
 
I'm using the same code as you, except that I added a CType() conversion

If I add a 150K JPG file in at design time, it blows up with the same error during InitializeComponent
Me.p.Image = CType(resources.GetObject("p.Image"), System.Drawing.Image
 
Can you successfully load small jpg's (5K, 10K, etc.)?

--
Tim Wilson
..Net Compact Framework MVP

Kurtis said:
I'm using the same code as you, except that I added a CType() conversion.

If I add a 150K JPG file in at design time, it blows up with the same
error during InitializeComponent:
 
Yes. The code works fine for smaller files. I've seen some other threads that mention a limit to the bit map size, but I can’t find anything definite.

This same code works fine in a Win32 app, so it seems to be a limitation in the Compact Frame work.

I’m wondering if there’s another way to do this. Like API calls.
 
How much memory do you have. My *guess* is that when you load the JPG, it
uncompresses into an in-memory Bitmap, which is way bigger than the original
JPG, and your device is probably running out of memory.

-Chris


Kurtis said:
Yes. The code works fine for smaller files. I've seen some other threads
that mention a limit to the bit map size, but I can't find anything
definite.
 
In the past I've seen JPEG files that would not load in the Bitmap
constructor. It was supposed to be fixed between RTM and now, but I would
not bet on it

Kurtis said:
I have some code that loads JPG files into a PictureBox control. It works
fine if the file is small, but files over 100K cause an Argument Exception
error.
Since the compact frame work does not have:
picbox.image.fromfile("...")

I had to do it this way:
Dim MyImage As Bitmap
MyImage = New Bitmap(OpenFileDialog.FileName)
picbox.Image = CType(MyImage, Image)

It fails on New Bitmap(). I've seen other message threads about these bit
map size problem, but no solution.
 
Good point. I'm running it in the emulator and it looks like there is 3 to 4MB free. I've tried adjusting the memory bar and sometimes the error is OutOfMemoryError, other times it Argument error.

I get the same results running it on my pocketPC where I have 6MB and 15MB free memory.

If I'm scanning documents and transfering them to my PPC, should I save them in BMP format instead of JPEG?
 
It does seem to be memory related. I got better results on my Pocket PC than with the emulator which has more memory.

Is there a way to increase the memory setting on the emulator.
 
This is not adding up. I converted one of my test JPG files to a 900KB BMP file

When I run this on my PocketPC it has 6mb Free Storage and 9MB free Program memory prior to opening the file

It gives me an OutOfMemory error. How can it be be that opening a 1MB BMP file takes so much RAM?
 
Could you email me such a file (BMP)?

Kurtis said:
This is not adding up. I converted one of my test JPG files to a 900KB BMP file.

When I run this on my PocketPC it has 6mb Free Storage and 9MB free
Program memory prior to opening the file.
It gives me an OutOfMemory error. How can it be be that opening a 1MB BMP
file takes so much RAM?
 
Back
Top