       #endif
       temp_last = temp;
       temp = SPI.transfer(0x00); 
-      //Write image data to buffer if not full
+     if ((temp == 0xD8) & (temp_last == 0xFF))//find header
+    {
+      is_header = true;
+      buf[i++] = temp_last;
+      buf[i++] = temp;   
+    } 
+    if (is_header == true){
+           //Write image data to buffer if not full
       if (i < 256)
         buf[i++] = temp;
       else

    Serial.println("SD Card detected!");
}
void loop(){
  
  delay(5000);

}

        myCAM.CS_LOW();
        myCAM.set_fifo_burst();
        jpeg_size += 256;
      }   
    } 
  }
  buf[i++] = temp;  //save the last  0XD9  
    //Write the remain bytes in the buffer
    if (i > 0)
    {
