Trying to display a bitmap on T35 screen

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. As i have said i am new to C# so please give an example of code. Does anyone know the commands to display the image please?

Welcome!

Just follow Skewworks advise from the other thread. Also check the Codeshare section.

Ok thank you

i am still trying to display my background from my sd card it is exactly 320x240 for the screen size i am trying the coad
private void LoadBitmapFromSD()
{
string pathfilename = “\SD\Geek.bmp”;
GT.StorageDevice storage = sdCard.GetStorageDevice();
Debug.Print(“Geting File”);
Bitmap bitmap = storage.LoadBitmap(pathfilename, Bitmap.BitmapImageType.Bmp);
display_T35.SimpleGraphics.DisplayImage(bitmap, 0, 0);
}
but its giving me an error
Files available on \SD:
\SD\Geek.bmp
Folders available on \SD:
Accessing SD Card
Geting File
#### Exception System.IO.IOException - CLR_E_FILE_NOT_FOUND (1) ####
#### Message:
#### System.IO.FileStream::.ctor [IP: 00f2] ####
#### System.IO.File::ReadAllBytes [IP: 0008] ####
#### Gadgeteer.StorageDevice::LoadBitmap [IP: 0011] ####
#### GadgeteerApp1.Program::LoadBitmapFromSD [IP: 0021] ####
#### GadgeteerApp1.Program::ProgramStarted [IP: 0045] ####
#### GadgeteerApp1.Program::Main [IP: 0015] ####
A first chance exception of type ‘System.IO.IOException’ occurred in System.IO.dll
A first chance exception of type ‘System.IO.IOException’ occurred in System.IO.dll
An unhandled exception of type ‘System.IO.IOException’ occurred in System.IO.dll

any advice ?

Don’t see anything suspicious. Have you seen this entry on codeshare:

http://www.tinyclr.com/codeshare/entry/460

I got the coad from there i just cant get it to work i dont know if its something im leaving out or a problem with my.bmp
i am still learning if there is a post in coadshare i am not seeing point me at it pleas :slight_smile:

saying file not found. that is a clue.

its saying file not found right after it listed the file from sd card i dont know.
I am sorry if its something really simple or something that i just dont see i am new to this and am prone to mistakes
looking through the coad share page now

Show all code please. And please use code tags to make it more readable.

this is all i have at the moment its not much

[Code]
using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using Microsoft.SPOT.IO;

using System.Runtime .InteropServices;
using Gadgeteer.Modules.Seeed;

namespace GadgeteerApp1
{

public partial class Program
{
    // This method is run when the mainboard is powered up or reset.   
    void ProgramStarted()
    {
        Debug.Print("program Started");
     
        if (sdCard.IsCardInserted)
            sdCard.SDCardMounted += new SDCard.SDCardMountedEventHandler(sdCard_SDCardMounted);
        if (!sdCard.IsCardMounted)
            Debug.Print("SD Card Mounted");
      
       getFoldersandFiles();
       LoadBitmapFromSD();
       {
                }
    }        
          
    void sdCard_SDCardMounted(SDCard sender, GT.StorageDevice SDCard)
      {
        Debug.Print("SD card has been successfully mounted. You can now read/write/create/delete files");
        Debug.Print("Unmount before removing");
       }
       private void LoadBitmapFromSD()
       {
        string pathfilename = "\\SD\\Geek.bmp";
        GT.StorageDevice storage = sdCard.GetStorageDevice();
        Debug.Print("Geting File");
        Bitmap bitmap = storage.LoadBitmap(pathfilename, Bitmap.BitmapImageType.Bmp);
        display_T35.SimpleGraphics.DisplayImage(bitmap, 0, 0);
        }

    private void getFoldersandFiles()
    {
        if (VolumeInfo.GetVolumes()[0].IsFormatted)
          Debug.Print("Getting files and folders:");
        string rootDirectory =
            VolumeInfo.GetVolumes()[0].RootDirectory;
        string[] files = System.IO.Directory.GetFiles(rootDirectory);
        string[] folders = System.IO.Directory.GetDirectories(rootDirectory);
       
        Debug.Print("Files available on " + rootDirectory + ":");
        for (int i = 0; i < files.Length; i++)
            Debug.Print(files[i]);

        Debug.Print("Folders available on " + rootDirectory + ":");
        for (int i = 0; i < folders.Length; i++)
            Debug.Print(folders[i]);
    }

        }

    }

Using code tags will make your post more readable. This can be done in two ways:[ol]
Click the “101010” icon and paste your code between the

 tags or...
Select the code within your post and click the "101010" icon.[/ol]
(Generated by QuickReply)
And the quickest way to do this is to edit your post, highlight your code block, and hit the "101010" button near the TOP of your post

thank you sorry

I don’t see where do you call MountSdCard. You need to call that method where you check if it is inserted for example.

Thank you ill work on it

also check your logic. if an sd is not present, the load routine is still called from ProgramStarted.

it takes a while for the sd card to be mounted.

Ok I have tryed a few diffrent things however i see the same result. I added in what you said and called it with a thread sleep to allow it to finish mount


namespace GadgeteerApp1
{

    public partial class Program
    {
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            Debug.Print("program Started");
           sdCard.DebugPrintEnabled = true;
           sdCard.SDCardMounted +=new SDCard.SDCardMountedEventHandler(sdCard_SDCardMounted);
                  
           display_T35.SimpleGraphics.Clear();
           sdCard_SDCardMount();
           Thread.Sleep(1000);
           getFoldersandFiles();
           LoadBitmapFromSD();
           {
           }
           }
          private void sdCard_SDCardMount()
           {
            if (sdCard.IsCardInserted)
            {
            sdCard.MountSDCard();
            Debug.Print("SD Card Mounted");
            }
            else
          Debug.Print("no SDcard");
           }            
      public void sdCard_SDCardMounted(SDCard sender, GT.StorageDevice SDCard)
           {
           }           
           private void LoadBitmapFromSD()
           { 
            string pathfilename = "\\SD\\Geek.bmp";
            GT.StorageDevice storage = sdCard.GetStorageDevice();
            Debug.Print("Geting File");
            Bitmap bitmap = storage.LoadBitmap(pathfilename, Bitmap.BitmapImageType.Bmp);
            display_T35.SimpleGraphics.DisplayImage(bitmap, 0, 0);
            }
        private void getFoldersandFiles()
            {
            if (VolumeInfo.GetVolumes()[0].IsFormatted)
              Debug.Print("Getting files and folders:");
            string rootDirectory =
                VolumeInfo.GetVolumes()[0].RootDirectory;
            string[] files = System.IO.Directory.GetFiles(rootDirectory);
            string[] folders = System.IO.Directory.GetDirectories(rootDirectory);           
            Debug.Print("Files available on " + rootDirectory + ":");
            for (int i = 0; i < files.Length; i++)
                Debug.Print(files[i]);
            Debug.Print("Folders available on " + rootDirectory + ":");
            for (int i = 0; i < folders.Length; i++)
                Debug.Print(folders[i]);
              }
              }
              }

One other thing you should do here is completely remove all that code from the ProgramStarted() method. The Gadgeteer scheduler most likely won’t interfere, but you should put your “doing work” into a timer that you run once to see if that assists.

Or move your image load call into card mounted event handler.

I am not sure if events get dispatched if you are in program started method.

Register for event and get out. Load from ad when you get the mounted event.
BTW, one second is not enough time for mount to occur. Never
a good practice to make assumptions about timing and use sleep

I had to reply…

I saw this post a few days ago and ‘thought’ that I had some code to read bitmaps from a SD Card.

Well, I had some code I posted awhile back that I know worked when using (4.1)…

My spider is now using 4.2.9.0 and I cannot read bitmaps from the SD Card.

  1. I CAN write and read text files to the SD Card.

  2. I CAN write bitmaps to the SD Card.

  3. I CANNOT read the bitmaps back from the SD Card.
    I always receive the following: #### Exception System.IO.IOException - CLR_E_FILE_NOT_FOUND (1) ####

Could be me but I think the code I am using should work.

Partial code based on code that worked before



//Create a Bitmap, Display on LCD, save to SD Card - The bitmap file on the SD Card looks correct and I can read/edit it on my PC.

         private void button_ButtonPressed(Button sender, Button.ButtonState state)
         {
                imageGeneral = new Bitmap(SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight);
                imageGeneral.Clear();
                // Create bitmap image
                //DrawRectangle(Color, 0, position x, position y, rectangle width, rectangle height, ...
                //Position x/y for General data display
                imageGeneral.DrawRectangle(Colors.White, 0, 0, 0, 320, 240, 0, 0, Colors.White, 0, 0, Colors.White, 0, 0, Bitmap.OpacityOpaque);
                imageGeneral.DrawText("L1 (Y Position 1) bitmap imageGeneral text", baseFont, Colors.Black, 1, 0);
                imageGeneral.DrawText("L2 (Y Position 18)", baseFont, Colors.Black, 1, pos);
                imageGeneral.DrawText("L3 (Y Position 36)", baseFont, Colors.Red, 1, pos += spacing);
                imageGeneral.DrawText("L4 (Y Position 54)", baseFont, Colors.Red, 1, pos += spacing);
                imageGeneral.DrawText("L5 (Y Position 72)", baseFont, Colors.Yellow, 1, pos += spacing);
                imageGeneral.DrawText("L6 (Y Position 90) ", baseFont, Colors.Yellow, 1, pos += spacing);
                imageGeneral.DrawText("L7 (Y Position 108)", baseFont, Colors.Brown, 1, pos += spacing);
                imageGeneral.DrawText("L8 (Y Position 126)", baseFont, Colors.Brown, 1, pos += spacing);
                imageGeneral.DrawText("L9 (Y Position 144)", baseFont, Colors.Black, 1, pos += spacing);
                imageGeneral.DrawText("L10 (Y Position 162)", baseFont, Colors.Green, 1, pos += spacing);
                imageGeneral.DrawText("L11 (Y Position 180)", baseFont, Colors.Green, 1, pos += spacing);
                imageGeneral.DrawText("L12 (Y Position 198)", baseFont, Colors.Purple, 1, pos += spacing);
                imageGeneral.DrawRectangle(Colors.Yellow, 0, 0, 221, 320, 18, 0, 0, Colors.Yellow, 0, 0, Colors.Yellow, 0, 0, Bitmap.OpacityOpaque);
                imageGeneral.DrawText("Last line of imageGeneral text", baseFont, Colors.Orange, 1, 222);

                //imageMain to LCD
                imageGeneral.Flush();

                //Save the bitmap to SD card
                saveBitmapimageGeneral();

                imageGeneral.Dispose();
        }
            
        private void saveBitmapimageGeneral()
        {
            // Save imageGeneralNew to SD card

            if (CheckforSDCard() && clicktimes == 1)
            {
                button.TurnLEDOff();
                GT.StorageDevice storage = sdCard.GetStorageDevice();

                // allocate buffer
                byte[] outputFile = new byte[imageGeneral.Width * imageGeneral.Height * 3 + 54];  //* 3 + 54 (3 colors)
                // convert to BMP file
                Util.BitmapToBMPFile(imageGeneral.GetBitmap(), imageGeneral.Width, imageGeneral.Height, outputFile);

                string pathFileName = "\\SD\\imageGeneralNew.bmp";
                try
                {
                    File.WriteAllBytes(pathFileName, outputFile);
                    Debug.Print("Saved imageGeneralNew.bmp to file: " + pathFileName);
                }
                catch (Exception ex)
                {
                    Debug.Print("Message: " + ex.Message + "  Inner Exception: " + ex.InnerException);
                }
            }
            button.TurnLEDOn();
        }
        //

        //Used to read saved bitmap

        private void LoadBitmapFromSD()
        {   
            // Save imageGeneral to SD card
            if (CheckforSDCard())
            {
                savefinished = false;
                button.TurnLEDOff();
                savefinished = false;
                string pathFileName = "\\SD\\imageGeneralNew.bmp";
                GT.StorageDevice storage = sdCard.GetStorageDevice();
                
                //Exception using storage.LoadBitmap
                #### Exception System.IO.IOException - CLR_E_FILE_NOT_FOUND (1) ####
                #### Message: 
                #### System.IO.FileStream::.ctor [IP: 00f2] ####
                #### System.IO.File::ReadAllBytes [IP: 0008] ####
                #### Gadgeteer.StorageDevice::LoadBitmap [IP: 0011] ####

                //Path shown from watch "\\SD\\imageGeneralNew.bmp"

                Bitmap bitmap = storage.LoadBitmap(pathFileName, Bitmap.BitmapImageType.Bmp); //Bitmap returns null

                display.SimpleGraphics.Clear();
                Thread.Sleep(2000);
                display.SimpleGraphics.DisplayImage(bitmap, 0, 0);
                savefinished = true;
                button.TurnLEDOn();
            }
        }
        //


Not sure why the path would fail? That is where the file is on the card.

NOTE: I used the Microsoft and SDFormatter 4.0 to format the SD Card. It made no difference.

SDFormatter 4.0 is from SD Association

Anyone see where I went wrong?

Have a GREAT Day!

EDIT:
I should have mentioned that I was using StreamWriter to write text
and FileStream to read the text.
Actually I used the sample code from TINYCLR WIKI SD Card Module for text.