MyException - 我的异常网
当前位置: 我的异常网 » 移动开发 » 手机拍照或选择相册,类似新浪微博的图片处理

手机拍照或选择相册,类似新浪微博的图片处理

www.MyException.Cn,网友分享于:2012-06-30   浏览:13次
手机照相或选择相册,类似新浪微博的图片处理

拍照的

		btn1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

				File out = new File(Environment.getExternalStorageDirectory(),
						"camera.png");
				Uri uri = Uri.fromFile(out);
				intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
				xxActivity.startActivityForResult(intent, 3);
							}
		});

 

相册

	btn2.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
				intent.addCategory(Intent.CATEGORY_OPENABLE);
				intent.setType("image/*");
				intent.putExtra("crop", "true");
				intent.putExtra("aspectX", 1);
				intent.putExtra("aspectY", 1);
				intent.putExtra("outputX", 80);
				intent.putExtra("outputY", 80);
				intent.putExtra("return-data", true);

				xxActivity.startActivityForResult(intent, 2);
							}
		});

 

处理的activity

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (resultCode != RESULT_OK) {
			return;
		} else {

			switch (requestCode) {
			case 2:
				Bitmap cameraBitmap = (Bitmap) data.getExtras().get("data");
				Home.personalinfo.headbmp = cameraBitmap;
				try {
					String str = saveMyBitmap(cameraBitmap);
				

				} catch (IOException e) {
					e.printStackTrace();
				}

				break;

			/* 拍照后保存图片,并跳到裁剪功能 */
			case 3:

				new saveAsy().execute("");
				break;
			}

		}
		super.onActivityResult(requestCode, resultCode, data);
	}

 saveAsy的方法

	class saveAsy extends AsyncTask<String, Object, String> {





		@Override
		protected String doInBackground(String... str) {
			dispathBitmap();
			Intent intent = new Intent("com.android.camera.action.CROP");
			try {
				intent.setData(Uri
						.parse(android.provider.MediaStore.Images.Media
								.insertImage(getContentResolver(),
										storageUrl+"/camera.png", null, null)));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
			intent.putExtra("crop", "true");
			intent.putExtra("aspectX", 1);
			intent.putExtra("aspectY", 1);
			intent.putExtra("outputX", 80);
			intent.putExtra("outputY", 80);
			intent.putExtra("return-data", true);
			startActivityForResult(intent, 2);

			return "";
		}

		@Override
		protected void onPostExecute(String bmp) {
			super.onPostExecute(bmp);

		}

	}

 

1 楼 yinhe625 2011-12-19  
楼主代码好像不全阿,可否分享下demo?414602238@qq.com 感谢!
软件开发程序错误异常Exception Copyright © 2009-2015 MyException 版权所有