How to change image format from JPEG to PNG in Android?

I open the camera of the Android device by default, conveying the intention. Therefore, when an image is captured, by default the camera saves it in JPEG format. But I do not want to store them in a lossy format. I want image quality to be high. So, how can I save it in PNG format? ...

here is my code to open the camera:

Date dt = new Date();     
        int date=dt.getDate();  
        int hours = dt.getHours();     
        int minutes = dt.getMinutes();   
        int seconds = dt.getSeconds();     
        String curTime = date+"_"+hours + "_"+minutes + "_"+ seconds;  
         _path=Environment.getExternalStorageDirectory() +"/"+curTime+".jpg";  
        File file = new File( _path );  
        Uri outputFileUri = Uri.fromFile( file );  
        Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );  
    intent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );  

 context.startActivityForResult(intent,0);  

Then process onActivutyForResult () {....}

Thanks Sneha

+5
source share
1 answer

I have not come across any way for the camera to save the file as PNG.

But you can convert the JPEGimage to format PNG.

try {
       FileOutputStream out = new FileOutputStream(filename);
       bmp.compress(Bitmap.CompressFormat.PNG, 100, out); //100-best quality
       out.close();
} catch (Exception e) {
       e.printStackTrace();
}

, . "" . .

+22

All Articles