How to change the image format from JPEG to PNG in android?

你离开我真会死。 提交于 2019-12-18 12:01:46

问题


I am opening the default android device camera by passing an intent. So when an image is captured, by default, camera stores it in JPEG format. But I don't want to store them in lossy format. I want picture quality to be high. So how can i store it in PNG format?...

here goes my code to open 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 handle onActivutyForResult (){....}

Thanks Sneha


回答1:


I haven't come across any method to make the camera save the file as PNG.

But you could convert the JPEG Image into PNG format.

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

Note, this won't enhance the quality. You cannot "increase" the information in an image. This will only change the Image Format.



来源:https://stackoverflow.com/questions/8474032/how-to-change-the-image-format-from-jpeg-to-png-in-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!