- 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()));
- }
- }
相关文章
- 08-24Android 学习笔记进阶十二之裁截图片
- 08-24Android 学习笔记进阶14之像素操作
- 08-24Android学习笔记进阶20 之得到图片的缩略图
- 08-24Android学习笔记进阶19 之给图片加边框
- 08-24Android学习笔记进阶21之设置壁纸
- 08-24Android学习笔记(二)之异步加载图片
- 08-24Android学习笔记之详细讲解画圆角图片
- 08-24Android(java)学习笔记236:多媒体之加载大图片到内存(Bitmap API)
- 08-24Android学习笔记进阶17之LinearGradient
- 08-24Android学习笔记进阶16之BitmapShader