加载手机磁盘里的图片文件(BitmapFactory.decodeFile()
来源:互联网 发布:咸鱼搜索知乎 编辑:程序博客网 时间:2024/05/15 00:23
加载手机磁盘里的图片文件(BitmapFactory.decodeFile()
新建一个继承Activity类的BitmapFactoryDeocdeFileActivity,并设置布局文件为:bitmapdecodefile.xml。
在布局文件中添加一个Button和一个ImageView组件
<Button
android:id="@+id/bitmapfactorydecodefile_btn"
style="@android:style/Widget.Button.Inset"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/change"/>
<ImageView
android:id="@+id/bitmapfactorydecodefile_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
而后在代码中实现点击后打开一张手机里面的图片
package lyx.feng.second;
......
public class BitmapFactoryDeocdeFileActivity extends Activityimplements
OnClickListener {
private Buttonbtn = null;
private ImageViewimage = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.bitmapdecodefile);
// 取得组件,注册按钮事件
this.btn = (Button)super
.findViewById(R.id.bitmapfactorydecodefile_btn);
this.image = (ImageView)super
.findViewById(R.id.bitmapfactorydecodefile_image);
this.btn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// 得到一个图片用于保存到内存中
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.icon_002);
File file = new File("data/data/lyx.feng.simpletextdemo/image.png");
if (!file.exists()) {
// 如果文件不存在就保存一张图片到File中
try {
FileOutputStream stream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} else {
bitmap = null;
// 读取图片到ImageView中
bitmap = BitmapFactory
.decodeFile("data/data/lyx.feng.simpletextdemo/image.png");
this.image.setImageBitmap(bitmap);
}
}
}
- 加载手机磁盘里的图片文件(BitmapFactory.decodeFile()
- Android 使用decodeFile方法加载手机磁盘中的图片文件
- 加载手机存储卡中的图片BitmapFactory.decodeFile()
- 屏幕密度掺入BitmapFactory里decodeFile与decodeResource的差异
- 屏幕密度掺入BitmapFactory里decodeFile与decodeResource的差异
- 屏幕密度掺入BitmapFactory里decodeFile与decodeResource的差异
- BitmapFactory.decodeFile
- BitmapFactory.decodeFile图片过大内存溢出
- Android随记------屏幕密度掺入BitmapFactory里decodeFile与decodeResource的差异
- BitmapFactory.decodeFile载入的图片和图片在drawable文件夹中的关系
- BitmapFactory.decodeFile 加载失败 在部分安卓机器的BUG
- BitmapFactory.decodeFile能否对一张来自HTTP的图片进行解码呢
- BitmapFactory.decodeFile能否对一张来自HTTP的图片进行解码呢
- android 入门基础(10) ------ intent加载手机磁盘的图片文件
- BitmapFactory 方法:decodeFileDescriptor()、decodeFile()
- BitmapFactory.decodeFile返回NULL
- 加载手机磁盘中的文件
- BitMapFactory.decodeFile always returns null.
- 00002笔试题(JAVA)
- RatingBar自定义图片大小如何确定
- Android群英传笔记——第三章:Android控件架构与自定义控件讲解
- 资深架构师如何看待大型网站系统架构
- MVC 3 数据验证 Model Validation 详解
- 加载手机磁盘里的图片文件(BitmapFactory.decodeFile()
- 异步消息系统实践
- 常用 Windows 7运行命令大全
- C# 动态创建控件数组并赋值
- Git与github使用
- 建立个人简易的SMB服务器指南
- Android Design Support Library之NavigationView
- 以“栈”为底(一)
- JAVA SE——集合