读取assets中的图片
来源:互联网 发布:mac的library在哪 编辑:程序博客网 时间:2024/05/20 11:20
今天公司有一个游戏需要改造,电脑上找不到游戏的源码,因此,只能反编译来修改,然后重新打包、签名出包。。。
自己先写一个Demo实现要实现的功能,然后打包,再进行反编译将里面的文件拷贝到原游戏反编译后相对应的文件夹中。Demo中有一个加载图片的功能,使用的是直接从drawable中获取,因此图片会在R文件中生成一个int值,可能跟游戏本身中的R文件中的int重复了,导致出错。
为了解决加载图片不要出错,采用了从assets中读取文件的方法。以下是实现的demo:
@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);LinearLayout layout = new LinearLayout(this);layout.setOrientation(LinearLayout.VERTICAL);ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);layout.setLayoutParams(params);ImageView iv = new ImageView(this);ViewGroup.LayoutParams iv_params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);iv.setLayoutParams(iv_params);iv.setImageBitmap(getImageFromAssetsFile("a_warn.jpg"));layout.addView(iv);setContentView(layout);new Handler().postDelayed(new Runnable() {@Overridepublic void run() {Intent intent = new Intent(AppActivity.this, PopDiamond.class);startActivity(intent);AppActivity.this.finish();}}, 3000);}private Bitmap getImageFromAssetsFile(String fileName) { Bitmap image = null; AssetManager am = getResources().getAssets(); try { InputStream is = am.open(fileName); image = BitmapFactory.decodeStream(is); is.close(); } catch (IOException e) { e.printStackTrace(); } return image; }其中从assets读取图片的实现方法为:(可以直接copy调用)
private Bitmap getImageFromAssetsFile(String fileName) { Bitmap image = null; AssetManager am = getResources().getAssets(); try { InputStream is = am.open(fileName); image = BitmapFactory.decodeStream(is); is.close(); } catch (IOException e) { e.printStackTrace(); } return image; }
0 0
- 读取assets中的图片
- 读取assets文件夹中的图片
- 读取Assets中的文件
- 读取assets中的文件
- Android 读取Assets中图片
- Android 读取Assets中图片
- Android 读取Assets中图片
- Android 读取Assets中图片
- 从Assets中读取图片
- Android 读取Assets中图片
- 从Assets中读取图片
- Android 读取Assets中图片
- assets目录中的资源读取
- 读取Assets中的文件数据
- 读取assets目录中的文件
- Android读取assets中的文件
- 读取Assets文件夹中的文件
- 读取Assets文件夹中的文件
- 吐血分享android学习,安卓资源,自学资源
- 金额计算以及格式转换
- Linux服务器时间相关结构体和函数整理
- Oracle 查询连续的年份
- 简单选择排序(该出手时才出手)
- 读取assets中的图片
- 防止MTU设置不合理导致的链路不通问题
- 一、ngCookies 模块
- Linux 与 BSD 有什么不同?
- 从一个简单查找问题看算法的魅力
- Vultr CentOS6.8换内核装锐速
- 前端开源项目周报0221
- UDP主要丢包原因及具体问题分析
- 文章标题