Android 学习笔记进阶十二之裁截图片
2024-08-26 05:20:59
- package xiaosi.cut;
- import java.io.File;
- import android.app.Activity;
- import android.content.Intent;
- import android.graphics.drawable.Drawable;
- import android.net.Uri;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.ViewGroup.LayoutParams;
- import android.widget.Button;
- public class CutActivity extends Activity {
- private static int SELECT_PICTURE;//返回标志位 filed
- private File tempFile;
- private Button button;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- //setContentView(R.layout.main);
- this.tempFile = new File("/sdcard/song/a.jpg");
- button = new Button(this);
- button.setText("获取图片");
- button.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
- intent.setType("image/*");
- intent.putExtra("crop", "true");// crop=true 有这句才能出来最后的裁剪页面.
- intent.putExtra("aspectX", 1);// 这两项为裁剪框的比例.
- intent.putExtra("aspectY", 2);// x:y=1:2
- intent.putExtra("output", Uri.fromFile(tempFile));
- intent.putExtra("outputFormat", "JPEG");//返回格式
- startActivityForResult(Intent.createChooser(intent, "选择图片"), SELECT_PICTURE);
- }
- });
- setContentView(button);
- }
- /**
- * 裁剪完图片后系统调用的方法:onActivityResult
- */
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (resultCode == RESULT_OK)
- if (requestCode == SELECT_PICTURE)
- button.setBackgroundDrawable(Drawable.createFromPath(tempFile.getAbsolutePath()));
- }
- }
最新文章
- Issue 5:Hadoop博客系列转载
- [C#高级编程]基础知识摘要一
- git将本地仓库上传到远程仓库
- [转]如何编写和应用Java的自定义异常类
- Linux下进程通信的八种方法
- OpenGL ES 的三种变量类型(uniform,attribute和varying)
- WSAWaitForMultipleEvents()
- CentOS 7 安装MySql Server 5.6
- JS window.open()财产
- spring boot / cloud (八) 使用RestTemplate来构建远程调用服务
- 【BZOJ3685】【zkw权值线段树】普通van Emde Boas树
- centos安装谷歌浏览器
- SQL Server 之 事务与隔离级别实例讲解
- 关于Linux前后台进程切换
- java工程师需要学什么
- CMD命令行下修改网络IP设置的方法
- async await yield
- Mysql的基本语句
- C#读取excel文件,并生成json
- java.lang.NoClassDefFoundError: Could not initialize class com.demo.jdbc.utils.MyJdbcUtils
热门文章
- The evolution of cluster scheduler architectures--转
- Spring深入浅出(二)IOC的单例 ,继承,依赖,JDBC,工厂模式以及自动装载
- 服务器http处理流程
- WIFI 概览
- python 代码编写规范
- 「BZOJ3343」教主的魔法(分块+二分查找)
- Linux中常用命令(文件与目录)
- lsof---查看你进程开打的文件
- ssh 免交互式登陆
- Configure Tomcat 7 to run Python CGI scripts in windows(Win7系统配置tomcat服务器,使用python进行cgi编程)