如何在android中将图像格式从JPEG更改为PNG? [英] How to change the image format from JPEG to PNG in android?

查看:14
本文介绍了如何在android中将图像格式从JPEG更改为PNG?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过传递一个意图来打开默认的 android 设备摄像头.因此,当捕获图像时,默认情况下,相机会将其存储为 JPEG 格式.但我不想以有损格式存储它们.我希望图像质量很高.那么如何将其存储为 PNG 格式呢?...

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

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

Then handle onActivutyForResult (){....}

谢谢斯内哈

推荐答案

我还没有遇到任何让相机将文件保存为PNG的方法.

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

但您可以将 JPEG 图像转换为 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.

这篇关于如何在android中将图像格式从JPEG更改为PNG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆