         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)
     {

      jpeg_size += i;
    }
    temp=0;temp_last=0;
    remnant = (4 - (jpeg_size & 0x00000003)) & 0x00000003;
    jpeg_size = jpeg_size + remnant;
    movi_size = movi_size + jpeg_size;

      #endif
      temp_last = temp;
      temp = SPI.transfer(0x00); 
     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
