把一张合成图分拆出各个小图

反编译一个程序,看到一张合成图,想分拆出里面的每个小图,知道了各个图的坐标大小后,写了一个小方法,希望对大家有用哈

package com.bitimage;import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Environment;public class BigImageToSmall extends Activity {@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);int[] ix = { 0, 0, 32, 64, 96, 128, 168, 208, 248, 0, 33, 66, 99, 132,150, 168, 132, 150, 168, 186, 204, 222, 186, 204, 222, 0, 0, 0,240, 240, 260, 260, 0, 31, 95, 159, 223, 700, 670, 670, 287, 0,260, 0, 12, 24, 36, 48, 60, 72, 84, 96, 108, 0, 670, 670, 0, 0,626, 648, 0, 298, 0, 288, 320, 0, 0, 670, 702, 734, 670, 702,734, 670, 702, 734, 670, 120, 130, 140, 150, 160, 170, 180,190, 200, 210, 702, 0, 0, 0, 0, 0, 320, 0 };int[] iy = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 42, 42, 42, 40, 40, 40, 58,58, 58, 40, 40, 40, 58, 58, 58, 76, 127, 144, 40, 57, 231, 248,280, 280, 280, 280, 280, 295, 234, 295, 280, 321, 153, 153,153, 153, 153, 153, 153, 153, 153, 153, 153, 355, 0, 139, 504,225, 0, 0, 170, 40, 425, 0, 263, 0, 0, 333, 333, 333, 380, 380,380, 427, 427, 427, 474, 153, 153, 153, 153, 153, 153, 153,153, 153, 153, 474, 0, 0, 0, 0, 0, 0, 459 };int[] iw = { 0, 32, 32, 32, 32, 40, 40, 40, 40, 33, 33, 33, 33, 18, 18,18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 290, 320, 294, 58, 48,58, 58, 31, 64, 64, 64, 64, 44, 80, 30, 31, 320, 50, 12, 12,12, 12, 12, 12, 12, 12, 12, 12, 310, 113, 110, 308, 260, 22,22, 260, 17, 320, 28, 202, 1, 1, 32, 32, 32, 32, 32, 32, 32,32, 32, 32, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 76, 1, 1,1, 1, 1, 306, 320 };int[] ih = { 0, 42, 42, 42, 42, 35, 35, 35, 35, 34, 34, 34, 34, 18, 18,18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 51, 17, 9, 17, 9, 17,17, 41, 41, 41, 41, 41, 24, 61, 32, 41, 34, 78, 17, 17, 17, 17,17, 17, 17, 17, 17, 17, 70, 139, 95, 40, 55, 520, 520, 55, 20,34, 36, 57, 1, 1, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 17,17, 17, 17, 17, 17, 17, 17, 17, 17, 48, 1, 1, 1, 1, 1, 263, 45 };System.out.println("ix length = " + ix.length);System.out.println("iy length = " + iy.length);System.out.println("iw length = " + iw.length);System.out.println("ih length = " + ih.length);FileOutputStream fos = null;for (int i = 1; i < 95; i++) {System.out.println(i);String aa = String.format("a%02d", i);File file = new File(Environment.getExternalStorageDirectory(), aa + ".png");
//			File file = new File(System.getProperty("user.dir"),"a"
//					+ i + ".png");System.out.println(file);if (!file.exists()) {try {file.createNewFile();} catch (IOException e) {e.printStackTrace();}}Drawable d = getResources().getDrawable(R.drawable.cs_jmp);BitmapDrawable bd = (BitmapDrawable) d;Bitmap bm = bd.getBitmap();Bitmap bitmap = Bitmap.createBitmap(bm, ix[i], iy[i], iw[i], ih[i]);ByteArrayOutputStream baos = new ByteArrayOutputStream();bitmap.compress(CompressFormat.PNG, 100, baos);InputStream in = new ByteArrayInputStream(baos.toByteArray());try {fos = new FileOutputStream(file);byte[] bytes = new byte[100];int tempbyte;while ((tempbyte = in.read(bytes)) != -1) {System.out.println("tempbyte = " + tempbyte);fos.write(bytes,0,tempbyte);}fos.flush();} catch (Exception e) {e.printStackTrace();} finally {if (fos != null) {try {fos.close();} catch (IOException e) {e.printStackTrace();}}if (in != null) {try {in.close();} catch (IOException e) {e.printStackTrace();}}}}}
}

  记得加权限哦

<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" />

  demo图片

转载于:https://www.cnblogs.com/ycclmy/p/3939125.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/420633.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

6_js数组常用函数进阶与String

1 数组常用函数的应用 1.1 数组常用方法解析进阶 文档&#xff1a;const - JavaScript | MDN 课堂案例&#xff1a;01.find&Some方法的应用.html find() 从数组中找到满足条件的第一个元素并且并返回它。否则返回 undefined。 findIndex()*方法返回数组中满足提供的测试…

vue-快速原型开发

官方地址&#xff1a; https://cli.vuejs.org/zh/guide/prototyping.html

mybatis TypeHandler 类型处理器

目录1. 自定义日期类型处理器2. 配置自定义日期处理器3. 新增&#xff0c;查询1. 自定义日期类型处理器 继承mybatis提供的BaseTypeHandler覆写方法&#xff0c; 来转换Java和数据库中的字段package cn.bitqian.config;import org.apache.ibatis.type.BaseTypeHandler; import…

使用map递归树形结构

mapTree (data) {const reg /^e/;const regu /^u/;data.map(items > {if(items.children.length < 1){if(reg.test(items.userid)){items.disabled true //遍历树 拼入相应的disabled}else if(regu.test(items.userid)){items.children undefined }}else{this.mapTr…

分页查询插件PageHelper 5.x版本

目录1. jar包依赖2. mybatis核心文件配置3. 简简单单分页1. jar包依赖 <!--分页助手--><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper</artifactId><version>5.2.0</version></dependency&…

适用于ELment-UI级联多选框,数据回填,根据子节点的值查找完整路径

适用于ELment-UI级联多选框el-cascader&#xff0c;数据回填&#xff0c;根据子节点的值查找完整路径 已知子元素id,怎么获取它所有的父元素&#xff1f;用递归实现 /*** 查找匹配的完整路径* id: 匹配的值* data: 匹配的数组数据* prop: 匹配的字段名*/searchPath (id, …

多表操作查询 一对一

目录1. 一对一关系2. 一对一外键关联查询配置1. 一对一关系 数据库中的一对一关系 – 主键关联和外键关键 如person表和身份证表card 1、主键关联 create table person (pid int primary key auto_increment,pname varchar(40) not null,pgender varchar(10) not null )crea…

BZOJ-1045 糖果传递

先拆成链的情况来看。 设B[i]表示i要向i1拿糖果的数量&#xff0c;C为平均数&#xff0c;则B[i] C - A[i] B[i-1] Answer就是B的绝对值之和 现在来看环的情况&#xff0c;也就是说B[n]指的是n要向1拿糖果的数量。不妨设B[n]为K&#xff0c;则B[1] C - A[1] K………… 照着式…

一对多,多对多查询

1. 一对多配置 1. 什么是一对多 如用户表和订单表&#xff0c; 单个用户可能有多个订单&#xff0c;即一对多。如班级表和学生表 一个班级有多个学生&#xff0c;学生表的外键为 班级表的主键。如下面就是一对多&#xff0c;查询用户对应的订单配置 <?xml version"1…

优化JS代码的34种方法(上)

1. 含有多个条件的if语句 //longhand if(x abc || x def || x ghi || x jkl){//logic }//shorthand if([abc,def,ghi,jkl].includes(x)){//logic }2. if…else的缩写法 当我们在if-else条件下的逻辑比较简单时&#xff0c;我们可以使用三元条件运算符。 //longhand let …

稀疏表示

稀疏表示是近期几年信号处理领域的热点之中的一个&#xff0c;简单来说&#xff0c;它事实上是一种对原始信号的分解过程&#xff0c;该分解过程借助一个事先得到的字典&#xff08;也有人称之为过完备基&#xff0c;overcomplete basis&#xff0c;后面会介绍到&#xff09;&a…

一对一,一对多,多对多查询 (注解写法)

目录1、实体2、一对一3、一对多4、多对多5、测试核心&#xff1a; 一对一&#xff0c;注解&#xff1a;Select Results Result One 一对多 & 多对多&#xff0c;One改为Many共同的操作&#xff1a;查询多表时&#xff0c;先查一个表&#xff0c; 把这个实体属性作为查询条件…

Linux内核中影响tcp三次握手的一些协议配置

在Linux的发行版本中&#xff0c;都存在一个/proc/目录&#xff0c;有的也称它为Proc文件系统。在 /proc 虚拟文件系统中存在一些可调节的内核参数。这个文件系统中的每个文件都表示一个或多个参数&#xff0c;它们可以通过 cat 工具进行读取&#xff0c;或使用 echo 命令进行修…

ssm整合 durid数据源 报错java.sql.SQLException: Access denied for user ‘xxx‘@‘localhost‘

目录1、报错原因2、如何解决1、报错原因 连接数据库账号密码错误… 但我在jdbc.properties中检查账号&#xff0c; 密码都是正确的呀&#xff0c;&#x1f623; drivercom.mysql.cj.jdbc.Driver urljdbc:mysql://localhost:3306/mybatis_study?serverTimezoneGMT usernamer…

CS无线电语

〔Radio Commands (" Z "键) - 无线电指令〕1."Cover me" (掩护我)2."You Take The Point"(你守住这个位置)3."Hold This Position"(各单位保持现在的位置)4."REGROUP TEAM"(重新组队)&#xff0c;队友过于分散的时候可以用…

ssm整合 报错org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):xxx

目录1. 报错原因2. 解决3. 说明1. 报错原因 使用MapperScannerConfigurer扫描对应的mapper接口&#xff0c;帮我把mapper放入spring容器中&#xff0c;但是我的mapper映射文件并没有关联到sessionFactory中。 加载mybatis核心配置文件时&#xff0c; 其中的环境&#xff0c;数…

Teradata Fastload 使用方法

第一步&#xff1a; 首先打开 teradata fastload.exe 第二步&#xff1a; 通过粘贴导入脚本 脚本&#xff1a; SESSIONS 4; ERRLIMIT 25; SET RECORD VARTEXT ",";LOGON localhost/Teradata_Education,Educate; /* localhost:IP Address; Teradata_Education:user…

linux编译警告 will be initialized after

http://blog.chinaunix.net/uid-17019762-id-3152012.html 作为一个有强迫症的人&#xff0c;实在是受不了 warning 的存在 这个warning是由于初始化顺序引起的, // 会出现warning 的代码&#xff01;class cInit{public: cInit(std::string str, int a) : str_(str), a_(a…

Java实现邮箱发送(阿里云邮箱推送)

Java mail邮箱发送1. 邮箱信息实体类2. jar包依赖3. 发送邮箱实现绑定阿里云域名&#xff0c;创建域名账户&#xff0c;并配置解析域名账户&#xff0c;获得发送邮箱的权限&#xff0c;上限两百封&#xff0c;超出要&#xffe5;… 阿里云邮件推送控制台https://www.aliyun.co…

Android组件系列----BroadcastReceiver广播接收器

​【声明】 欢迎转载&#xff0c;但请保留文章原始出处→_→ 生命壹号&#xff1a;http://www.cnblogs.com/smyhvae/ 文章来源&#xff1a;http://www.cnblogs.com/smyhvae/p/3960623.html 【正文】 一、广播的功能和特征 广播的生命周期很短&#xff0c;经过调用对象-->…