Updated the file output stream to write bitmap to jpeg instead of raw data to jpeg. This should hopefully help fix the rotation issue