EMX : Display picture from SD / USB device

Hello and happy new year everyone!

To begin 2013 I am trying to achieve something simple with EMX module (but maybe not as simple that I expect):
I am trying to display a picture from Storage device to Glide.
I now how to display a picture pre- included in ressources manager, but don’t figure out how to deal with SD :

I have this code working with a picture from ressource manager :


windows[WIN_MAIN] = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.Window1_Main));
Image imageProg = (Image)windows[WIN_MAIN].GetChildByName("mouse");
imageProg.Bitmap = Resources.GetBitmap(Resources.BitmapResources.mouse_60x60);
Glide.MainWindow = windows[WIN_MAIN]; 

Then I would like to change it to something like :


windows[WIN_MAIN] = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.Window1_Main));
Image imageProg = (Image)windows[WIN_MAIN].GetChildByName("mouse");
imageProg.Bitmap =  new Bitmap("//SD//Grapes.bmp"); 
Glide.MainWindow = windows[WIN_MAIN]; 

But unfortunately, this function doesn’t exist !
I am currently trying to read the file on SD card, copy it in a byte array, and then feed the bitmap constructor new Bitmap(byteArray,Bitmap.BitmapImageType.Bmp) with this byte array…

How would you process the operation of reading the byte array from the file? Is it a good idea?
It seems a bit akward, I suspect there is a smarter way , anyone has an idea to display a pict from SD? with or without Glide.

Rgds

Have your tried using a FileStream to open the bitmap, and then fill a byte[] buffer with the stream.

Something like that :


FileStream fs = new FileStream(filelname, FileMode.Open, FileAccess.Read); 

Byte[] b = new Byte[fs.Length]; 
fs.Read(b, 0, (int) fs.Length); 
fs.Close(); 

Bitmap bp = new Bitmap(b, Bitmap.BitmapImageType.Bmp); 

1 Like

Thank you Louis CPro! It helps a lot : The code that you submitted is exactly what I was trying to do.
Since I really can’t find a shorter way to do that, (some direct function like : imageProg.Bitmap = new Bitmap("//SD//Grapes.bmp"); )
I will use your code to implement a CreateBitmapFromFile() function.

You’re welcome !