android调用系统资源裁剪图片
来源:互联网 发布:俄罗斯方块 软件测试 编辑:程序博客网 时间:2024/05/16 07:53
1 import java.io.File;
2 import android.app.Activity;
3 import android.content.Intent;
4 import android.graphics.drawable.Drawable;
5 import android.net.Uri;
6 import android.os.Bundle;
7 import android.view.View;
8 import android.view.View.OnClickListener;
9 import android.widget.Button;
10
11 public class GalleryActivity extends Activity {
12
13 private static int SELECT_PICTURE;//返回标志位 filed
14
15 private File tempFile;
16
17 Button button;
18
19 /** Called when the activity is first created. */
20 @Override
21 public void onCreate(Bundle savedInstanceState) {
22 super.onCreate(savedInstanceState);
23 this.tempFile = new File("/sdcard/a.jpg");// 这句一定要在onCreate()里面调用
24 button = new Button(this);
25 button.setText("获取图片");
26 button.setOnClickListener(new OnClickListener() {
27 @Override
28 public void onClick(View v) {
29 Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
30 intent.setType("image/*");
31 intent.putExtra("crop", "true");// crop=true 有这句才能出来最后的裁剪页面.
32
33 intent.putExtra("aspectX", 1);// 这两项为裁剪框的比例.
34 intent.putExtra("aspectY", 2);// x:y=1:2
35
36 intent.putExtra("output", Uri.fromFile(tempFile));
37 intent.putExtra("outputFormat", "JPEG");//返回格式
38
39 startActivityForResult(Intent.createChooser(intent, "选择图片"), SELECT_PICTURE);
40 }
41 });
42 setContentView(button);
43 }
44
45 /**
46 * 裁剪完图片后系统调用的方法:onActivityResult
47 */
48 @Override
49 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
50 if (resultCode == RESULT_OK)
51 if (requestCode == SELECT_PICTURE)
52 button.setBackgroundDrawable(Drawable.createFromPath(tempFile.getAbsolutePath()));
53 }
54 }
- android调用系统资源裁剪图片
- Android图片裁剪,合成(调用系统裁剪功能)
- [Android] 图片裁剪总结——调用系统裁剪
- hbuilder mui调用系统裁剪图片、头像裁剪-Android
- Android系统资源调用
- Android调用手机系统资源
- Android 调用相机、打开相册、裁剪图片
- Android 图片的裁剪与相机调用
- Android:调用系统图库/裁剪图片
- 调用Android系统相册并裁剪图片
- Android 调用相机或图库,裁剪图片
- Android调用系统裁剪图片模糊问题
- android图片选取与调用系统裁剪
- android 无法调用相册图片进行裁剪
- android调用原生剪裁界面裁剪图片
- Android调用系统图库并裁剪图片
- Android调用系统拍照裁剪图片模糊
- Android调用系统, 任意比例裁剪图片
- “漂”过2010
- 辞旧迎新
- 谁会是下一个扎克伯格
- 使用 WMSYS.WM_CONCAT 进行列转换
- 图形处理
- android调用系统资源裁剪图片
- 2010 -> 2011
- e5yetyty
- TCP无保护消息边界的解决
- QT学习(四)如何正确继承QWidget
- linux之ls -l|grep "^-"|wc -l命令
- 地球是烫的——低碳是人类的必然选择
- 正则表达式
- c#上传下载ftp(支持断点续传)