public voID onClick(VIEw v) { String imagefilename = "/sdcard/Penguins2.png"; file imagefile = new file(imagefilename); if (imagefile.exists()) { // Load the image from file myBitmap = BitmapFactory.decodefile(imagefilename); // display the image in the image vIEwer myImageVIEw = (ImageVIEw) findVIEwByID(R.ID.my_image_vIEw); if (myImageVIEw != null) { myImageVIEw.setimageBitmap(myBitmap); } } }
转换:
private voID processImage() { try { String outputPath = "/sdcard/Penguins2.jpg"; int quality = 100; fileOutputStream fileOutStr = new fileOutputStream(outputPath); bufferedoutputstream bufOutStr = new bufferedoutputstream( fileOutStr); myBitmap.compress(CompressFormat.JPEG,quality,bufOutStr); bufOutStr.flush(); bufOutStr.close(); } catch (fileNotFoundException exception) { Log.e("deBUG_log",exception.toString()); } catch (IOException exception) { Log.e("deBUG_log",exception.toString()); } myImageVIEw.setimageBitmap(myBitmap);
处理完这个 *** 作后,我只需更改这些行:
String imagefilename = "/sdcard/Penguins2.png";
至
String imagefilename = "/sdcard/Penguins2.jpg";
和
String outputPath = "/sdcard/Penguins2.jpg";(...)myBitmap.compress(CompressFormat.JPEG,bufOutStr);
至
String outputPath = "/sdcard/Penguins2.png";(...)myBitmap.compress(CompressFormat.PNG,bufOutStr);
图像尺寸从585847更改为531409(在DDMS中)
我想做这样的事情,因为我想使用PNG,它对于某些图像处理是无损的.
然后将图像转换为jpeg并发送为彩信,我不确定,但我认为JPEG只是MMS中所有设备支持的格式.接收器将打开图像并将其转换回png而不会丢失数据.
您可以看到PNG图像不使用质量参数:
总结quality: Hint to the compressor,0-100. 0 meaning compress for small size,100 meaning compress for max quality. Some formats,like PNG which is lossless,will ignore the quality setting
以上是内存溢出为你收集整理的位图在Android中压缩PNG – > JPEG,反之亦然全部内容,希望文章能够帮你解决位图在Android中压缩PNG – > JPEG,反之亦然所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)