1. package xiaosi.cut;
  2. import java.io.File;
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.graphics.drawable.Drawable;
  6. import android.net.Uri;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.view.View.OnClickListener;
  10. import android.view.ViewGroup.LayoutParams;
  11. import android.widget.Button;
  12. public class CutActivity extends Activity {
  13. private static int SELECT_PICTURE;//返回标志位 filed
  14. private File tempFile;
  15. private Button button;
  16. /** Called when the activity is first created. */
  17. @Override
  18. public void onCreate(Bundle savedInstanceState) {
  19. super.onCreate(savedInstanceState);
  20. //setContentView(R.layout.main);
  21. this.tempFile = new File("/sdcard/song/a.jpg");
  22. button = new Button(this);
  23. button.setText("获取图片");
  24. button.setOnClickListener(new OnClickListener() {
  25. public void onClick(View v) {
  26. Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
  27. intent.setType("image/*");
  28. intent.putExtra("crop", "true");// crop=true 有这句才能出来最后的裁剪页面.
  29. intent.putExtra("aspectX", 1);// 这两项为裁剪框的比例.
  30. intent.putExtra("aspectY", 2);// x:y=1:2
  31. intent.putExtra("output", Uri.fromFile(tempFile));
  32. intent.putExtra("outputFormat", "JPEG");//返回格式
  33. startActivityForResult(Intent.createChooser(intent, "选择图片"), SELECT_PICTURE);
  34. }
  35. });
  36. setContentView(button);
  37. }
  38. /**
  39. * 裁剪完图片后系统调用的方法:onActivityResult
  40. */
  41. @Override
  42. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  43. if (resultCode == RESULT_OK)
  44. if (requestCode == SELECT_PICTURE)
  45. button.setBackgroundDrawable(Drawable.createFromPath(tempFile.getAbsolutePath()));
  46. }
  47. }

最新文章

  1. Issue 5:Hadoop博客系列转载
  2. [C#高级编程]基础知识摘要一
  3. git将本地仓库上传到远程仓库
  4. [转]如何编写和应用Java的自定义异常类
  5. Linux下进程通信的八种方法
  6. OpenGL ES 的三种变量类型(uniform,attribute和varying)
  7. WSAWaitForMultipleEvents()
  8. CentOS 7 安装MySql Server 5.6
  9. JS window.open()财产
  10. spring boot / cloud (八) 使用RestTemplate来构建远程调用服务
  11. 【BZOJ3685】【zkw权值线段树】普通van Emde Boas树
  12. centos安装谷歌浏览器
  13. SQL Server 之 事务与隔离级别实例讲解
  14. 关于Linux前后台进程切换
  15. java工程师需要学什么
  16. CMD命令行下修改网络IP设置的方法
  17. async await yield
  18. Mysql的基本语句
  19. C#读取excel文件,并生成json
  20. java.lang.NoClassDefFoundError: Could not initialize class com.demo.jdbc.utils.MyJdbcUtils

热门文章

  1. The evolution of cluster scheduler architectures--转
  2. Spring深入浅出(二)IOC的单例 ,继承,依赖,JDBC,工厂模式以及自动装载
  3. 服务器http处理流程
  4. WIFI 概览
  5. python 代码编写规范
  6. 「BZOJ3343」教主的魔法(分块+二分查找)
  7. Linux中常用命令(文件与目录)
  8. lsof---查看你进程开打的文件
  9. ssh 免交互式登陆
  10. Configure Tomcat 7 to run Python CGI scripts in windows(Win7系统配置tomcat服务器,使用python进行cgi编程)