Android 学习笔记进阶十二之裁截图片
2017-04-17 14:04
441 查看
[java] view plain copy
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()));
}
}
相关文章推荐
- Android开发学习笔记(十二) 获取系统可用内存
- Android工作学习笔记之图片自适应imageview属性android:scaleType
- Android ExifInterface 学习笔记,图片旋转的操作。
- android 根据uri获取路径及图片压缩、旋转的学习笔记
- Android 学习笔记 第五季 12 图片处理
- Android中实现图片的异步加载学习笔记
- Android 实现图片缓存异步加载框架学习笔记
- Android学习笔记(二)之异步加载图片
- Android开发学习笔记(二):Android中插入图片资源
- android系统学习笔记十二
- Text-to-speech 入门与进阶学习笔记(android)
- android 多媒体部分学习笔记十二----mediaplay自定义播放器
- Android菜鸟学习笔记(ImageLoader加载图片)
- Android ExifInterface 学习笔记,图片旋转的操作。
- Android应用开发学习笔记之图片切换器
- ANDROID工作学习笔记之图片自适应IMAGEVIEW属性ANDROID:SCALETYPE
- Android ExifInterface 学习笔记,图片旋转的操作。
- maven 学习笔记(七)-(完整Android项目多渠道打包、签名、混淆进阶)
- Android 学习笔记 第五季 5 .9 图片
- Android ExifInterface 学习笔记,图片旋转的操作。