如何在安卓设备中将图片格式从JPEG转换为PNG?

6

我正在使用intent打开默认的安卓设备相机。当图片被拍摄时,默认情况下,相机将其存储为JPEG格式,但我不想以有损格式存储它们。我希望图片质量高,那么如何以PNG格式存储呢?...

这里是打开相机的代码:

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

然后处理onActivutyForResult()方法 {...}

谢谢 Sneha


仅仅因为它是JPEG格式并不意味着质量会很差...相机拍摄的图像将是高分辨率(默认设置),通常大小在500kB-2MB之间。 - st0le
1个回答

25

我还没有遇到过任何将照相机保存文件格式转换为PNG的方法。

但是你可以将JPEG图像转换为PNG格式。

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

请注意,这并不会提高图像的质量。您不能“增加”图像中的信息。这只会改变图像格式。


在Android中是否有任何图像压缩技术,以便我可以获得高质量的图像并将其存储在我的SD卡中,并发送到服务器? - Smitha
1
@Sneha,如果你需要高分辨率的图像,就不要使用任何压缩...只需发送相机意图提供的文件...那是你能得到的最好的。 - st0le
@st0le .. 在将类型转换为png后,其大小将会减小。 - Mohamad Mahmoud Darwish
根据Android文档,无损格式(如PNG)将忽略压缩质量参数。 - JP Ventura

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接