Android Activity之间传递图片(Bitmap)的方法
时间:2021-05-29 03:46:55
在Android开发中;Activity之间传递参数是常见的事;如果我们要在Activity之间传递图片;
1。MainActivity中包括一个ImageView;当我们点击ImageView时;把图片传递给另外一个Activity
MainActivity的主要代码:
Intent intent=new Intent(MainActivity.this,TranActivity.class);
intent.putExtra("bitmap", bitmap);
startActivity(intent);
biitmap是 在onCreate方法中获得的图片对象 bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
我们点击图片的时候,跳转到TranActivity中;并且传递一个Bitmap作为参数
2。在TranActivity中接收MainActivity传递过来的Bitmap;
imageview=(ImageView)findViewById(R.id.trans_imageview);
Intent intent=getIntent();
if(intent!=null)
{
bitmap=intent.getParcelableExtra("bitmap");
imageview.setImageBitmap(bitmap);
}
在TranActivity中获取Bitmap并给ImageView用来显示图片
3。通过接受图片之后,可以放大图片
imageview = (ImageView) findViewById(R.id.trans_imageview);
Intent intent = getIntent();
if (intent != null) {
bitmap = intent.getParcelableExtra("bitmap");
Matrix matrix = new Matrix(); //接收图片之后放大 1.5倍
matrix.postScale(1.5f, 1.5f);
Bitmap bit = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
bitmap.getHeight(), matrix, true);
imageview.setImageBitmap(bit);
}
运行效果
TranActivity;放大之后效果
标签:Android,Activity,传递图片
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C#中is,as,using关键字的使用说明
2023-07-01 22:54:42
![](https://img.aspxhome.com/file/2023/4/76394_0s.jpg)
Java常用类库Apache Commons工具类说明及使用实例详解
2021-06-08 12:34:17
![](https://img.aspxhome.com/file/2023/6/63326_0s.png)
C#命令模式用法实例
2021-10-21 12:46:02
C#实现单例模式的几种方法总结
2023-10-13 16:33:55
SpringBoot 静态资源导入及首页设置问题
2023-11-26 22:45:07
![](https://img.aspxhome.com/file/2023/0/59930_0s.png)
带大家认识Java语法之泛型与通配符
2021-06-04 06:14:46
![](https://img.aspxhome.com/file/2023/4/67494_0s.png)
Java Apache Shiro安全框架快速开发详解流程
2022-06-21 23:00:23
![](https://img.aspxhome.com/file/2023/8/69648_0s.png)
Java 入门图形用户界面设计之复选框
2022-06-19 15:22:53
![](https://img.aspxhome.com/file/2023/0/60540_0s.png)
C语言 MD5的源码实例详解
2022-12-22 05:37:16
使用SpringMVC访问Controller接口返回400BadRequest
2023-06-05 00:14:01
Java Socket编程(三) 服务器Sockets
2023-05-24 21:18:19
WPF实现带筛选功能的DataGrid
2022-05-07 07:48:56
![](https://img.aspxhome.com/file/2023/0/76430_0s.png)
C#使用Monitor类实现线程同步
2021-07-20 03:01:14
![](https://img.aspxhome.com/file/2023/3/67553_0s.png)
IDEA:Git stash 暂存分支修改的实现代码
2023-11-29 09:16:35
![](https://img.aspxhome.com/file/2023/3/78363_0s.jpg)
简单记事本java源码实例
2023-11-26 02:03:17
![](https://img.aspxhome.com/file/2023/4/59744_0s.jpg)
JS+Struts2多文件上传实例详解
2022-02-18 21:08:02
System.getProperty(user.dir)定位问题解析
2023-11-20 08:50:44
![](https://img.aspxhome.com/file/2023/8/79198_0s.png)
如何安装系统认证签名过的APK
2023-07-24 21:35:40
Java通过SSM完成水果商城批发平台流程
2023-01-04 01:32:04
![](https://img.aspxhome.com/file/2023/0/125510_0s.png)
springboot多环境配置文件及自定义配置文件路径详解
2021-09-30 03:55:54
![](https://img.aspxhome.com/file/2023/4/60844_0s.png)