android image 压缩和解压

android-sdk文件夹下platform存放的是android对应的平台
术语平台表示android本身(platform),包括所有的二进制文件、代码库和工具。SDK中提供的emulator只是android平台中到众多组件之一【google android 揭秘】

1.解压文件
下载工具 wget http://unyaffs.googlecode.com/files/unyaffs
并且增加执行权限 chmod 777 unyaffs
解压system.img和userdata.img
unyaffs ./your+image+name.img解压到当前文件夹
解压ramdisk.img
mv ramdisk.img ramdisk.gz
gunzip ramdisk.gz
cpio -id < ./ramdisk

2.压缩文件
mkyaffs2image命令完成压缩,该文件在android源码编译完后到out/host/linux-x86/bin
或者直接编译源码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java中可以使用`java.util.zip`包中的`ZipOutputStream`和`ZipEntry`类来实现图片的压缩和解压缩,下面是一个简单的示例代码: ### 压缩图片 ```java import java.io.*; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class ImageZip { public static void main(String[] args) { String srcFile = "src.jpg"; String zipFile = "src.zip"; try { // 创建ZipOutputStream对象 ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFile)); // 创建文件输入流对象 FileInputStream in = new FileInputStream(srcFile); // 创建ZipEntry对象 ZipEntry entry = new ZipEntry(srcFile); // 将ZipEntry对象加入到ZipOutputStream对象中 out.putNextEntry(entry); // 创建缓冲区 byte[] buffer = new byte[1024]; int len; // 读取文件内容,并写入ZipOutputStream对象中 while ((len = in.read(buffer)) > 0) { out.write(buffer, 0, len); } // 关闭文件输入流 in.close(); // 关闭ZipOutputStream对象 out.close(); System.out.println("压缩成功!"); } catch (IOException e) { e.printStackTrace(); } } } ``` ### 解图片 ```java import java.io.*; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class ImageUnzip { public static void main(String[] args) { String zipFile = "src.zip"; String destFile = "src.jpg"; try { // 创建ZipInputStream对象 ZipInputStream in = new ZipInputStream(new FileInputStream(zipFile)); // 获取ZipEntry对象 ZipEntry entry = in.getNextEntry(); // 创建文件输出流对象 FileOutputStream out = new FileOutputStream(destFile); // 创建缓冲区 byte[] buffer = new byte[1024]; int len; // 将ZipInputStream中的数据读取到文件输出流中 while ((len = in.read(buffer)) > 0) { out.write(buffer, 0, len); } // 关闭文件输出流 out.close(); // 关闭ZipInputStream对象 in.close(); System.out.println("解成功!"); } catch (IOException e) { e.printStackTrace(); } } } ``` 需要注意的是,上述示例代码仅适用于压缩和解单个图片文件。如果需要处理多个文件或文件夹,需要进行相应的修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值