相机
来源:互联网 发布:mac虚拟机都可以干什么 编辑:程序博客网 时间:2024/04/28 07:40
private Button button;
private ImageView view;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View inflate = inflater.inflate(R.layout.itme_4, container, false);
TextView viewById = inflate.findViewById(R.id.text_fram);
shand shand = new shand();
String getext = shand.getext(getActivity());
viewById.setText(getext);
button = inflate.findViewById(R.id.button);
view = inflate.findViewById(R.id.frment_4_image);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 1);
}
});
return inflate;
}
@SuppressLint("SdCardPath")
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode== Activity.RESULT_OK){
String sdStatus = Environment.getExternalStorageState();
if(!sdStatus.equals(Environment.MEDIA_MOUNTED)){//检测SD卡能否能用
Log.i("TestFile", "SD card is not avaiable/writeable right now.");
return;
}
String name = DateFormat.format("yyyyMMdd_hhmmss", Calendar.getInstance(Locale.CHINA)) + ".jpg";
Toast.makeText(getActivity(), name, Toast.LENGTH_LONG).show();
Bundle bundle = data.getExtras();
Bitmap bitmap = (Bitmap) bundle.get("data");// 获取相机返回的数据,并转换为Bitmap图片格式
FileOutputStream b = null;
File file = new File("/sdcard/Image/");
file.mkdirs();// 创建文件夹
String fileName = "/sdcard/Image/"+name;
try {
b=new FileOutputStream(fileName);
bitmap.compress(Bitmap.CompressFormat.JPEG,100,b);
} catch (FileNotFoundException e) {
e.printStackTrace();
}finally {
try {
b.flush();
b.close();
} catch (IOException e) {
e.printStackTrace();
}
}
view.setImageBitmap(bitmap);
}
}
}
private ImageView view;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View inflate = inflater.inflate(R.layout.itme_4, container, false);
TextView viewById = inflate.findViewById(R.id.text_fram);
shand shand = new shand();
String getext = shand.getext(getActivity());
viewById.setText(getext);
button = inflate.findViewById(R.id.button);
view = inflate.findViewById(R.id.frment_4_image);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 1);
}
});
return inflate;
}
@SuppressLint("SdCardPath")
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode== Activity.RESULT_OK){
String sdStatus = Environment.getExternalStorageState();
if(!sdStatus.equals(Environment.MEDIA_MOUNTED)){//检测SD卡能否能用
Log.i("TestFile", "SD card is not avaiable/writeable right now.");
return;
}
String name = DateFormat.format("yyyyMMdd_hhmmss", Calendar.getInstance(Locale.CHINA)) + ".jpg";
Toast.makeText(getActivity(), name, Toast.LENGTH_LONG).show();
Bundle bundle = data.getExtras();
Bitmap bitmap = (Bitmap) bundle.get("data");// 获取相机返回的数据,并转换为Bitmap图片格式
FileOutputStream b = null;
File file = new File("/sdcard/Image/");
file.mkdirs();// 创建文件夹
String fileName = "/sdcard/Image/"+name;
try {
b=new FileOutputStream(fileName);
bitmap.compress(Bitmap.CompressFormat.JPEG,100,b);
} catch (FileNotFoundException e) {
e.printStackTrace();
}finally {
try {
b.flush();
b.close();
} catch (IOException e) {
e.printStackTrace();
}
}
view.setImageBitmap(bitmap);
}
}
}
阅读全文
0 0
- 相机
- 相机
- 相机
- 相机
- 相机
- 相机
- 相机
- 相机
- 相机
- 买相机
- 相机分类
- 相机标定
- UIImagePickerController-相机
- 相机拍摄
- 相机参数
- 相机标定
- 相机像素
- 特殊相机
- android沉浸式
- 如何在三年内快速成长为一名专家
- 《云集的全链路压测之路》
- 机器学习之概率分布2
- 程序员跳槽全攻略,再不开窍过了30岁就要后悔!
- 相机
- css ~选择器的巧用
- Vue实践--过滤器(Filters)
- cJSON
- 避免 ScrollView 在 EditText 换行时自动滚动
- STM32F103C8T6学习笔记_中断
- 在线画图工具
- Eclipse项目文件被外部编辑器编辑后,Eclipse中的相对应文件自动刷新
- MyBatis源码(六)之动态Sql解析运行阶段BoundSql