trying to fix exceptions while saving jpeg to canvas