Main Site Documentation

Displaying a JPG from an SD card


#1

I have a program that I am writing that has many, many JPG images (269 to be exact). Rather than try to load these as resources, I opted to just load them on my SD card. What is the best way to display them on the LCD?


#2

I figured it out! :smiley:

			// Create a file stream object
			FileStream fHandle = new FileStream(@ "\SD\WX_Icons\someico.jpg", FileMode.Open, FileAccess.Read);

			// Create the byte array to hold the data
			byte[] data = new byte[fHandle.Length];

			// Copy the file data to the byte array
			fHandle.Read(data, 0, data.Length);

			// We're done.
			fHandle.Close();

			Bitmap wxIcon = new Bitmap(data, Bitmap.BitmapImageType.Jpeg);

			Image wxi = new Image(wxIcon);

Works just great!


#3

Well, that’s weird. It worked once, and now all I get is CLR_E_FILE_NOT_FOUND. I even confirmed that the file was on there.

Any ideas?


#4

I think I found a bug. Sometimes this works, sometimes it doesn’t.


#5

We would need more details and a way for us to reproduce the problem on our end.


#6

Hi Gus, I am going to send you an email… I was too tired to do it last night.


#7

Hey Chris!
Sorry to dust off an old topic, but I had a quick question.
I’m back working on my Cobra NVR project and doing a lot with displaying, saving, and loading jpg’s. A common problem I’m running into is the usual out of memory error when trying to move a jpg into a byte[] array, because once unpacked, the jpg becomes quite a large image.
I’m just wondering if you’ve run into this as well and might have found a clever way to manage this.
Right now I’m working with jpg’s of about 260KB and am hitting the error (1600x1200). If I use something smaller, on the order of 20KB (320x240), I have no problem.
Thanks, and I hope things are going well!

-Matt


#8

My Photo Frame project on the project wiki does this. I also handles determining the Bitmap Type automatically based on the file extension. I also ran into problems when the image was not very small … I had to resize them all to be no more than the resolution of my device. Until I did that, every other image load would throw a memory allocation error even though I had plenty of free memory for the image. Tried forcing a GC and that didn’t help either.

-Eric


#9

Eric:

Very nice project!

And here is the link to your project: :wink:

http://www.microframeworkprojects.com/index.php?title=Photo_Frame


#10

Hello all. First off I’m new to this fourm and to C# so i am going to ask a lot of dumb questions, so please excuse me. I have a Fez spider with a t35 display and SD card module. I have been researching and trying everything I can to get a image to display on my screen. I can get the text to show but I can’t seem to get the code correct. I am not having any trouble getting the SD card to mount or reading the files in output. Does anyone know the commands to display the image please?


#11

Just load it to a bitmap and .Flush() the bitmap to screen if its the exact size of the screen. Otherwise you need to draw it onto another bitmap that is the same size and flush that one.


#12

moving to new thread as requested http://www.tinyclr.com/forum/topic?id=10959