프로그래밍/android2011.04.26 16:02
private File getTempFile()
{
	return new File(Environment.getExternalStorageDirectory(), "image.jpg");
}

// 사진 촬영
private void doCaptureImage()
{
	Uri uri = Uri.fromFile(getTempFile());
	Log.e("###", getTempFile().toString());
	Log.e("###", uri.toString());
	
	Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
	intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
	startActivityForResult(intent, CAPTURE_IMAGE);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
	super.onActivityResult(requestCode, resultCode, intent);
	
	if (resultCode == RESULT_OK)
	{
		if (requestCode == CAPTURE_IMAGE)
		{
			Bitmap captureBmp = Media.getBitmap(getContentResolver(), Uri.fromFile(getTempFile()));
			String name = ="asdfqwer.jpg";
			File copyFile = new File(getFilesDir() + "/" + name);
			
			// 사이즈를 줄이지 않으니까 에러가 났다
			Bitmap resize = Bitmap.createScaledBitmap(captureBmp, 640, 480, true);
			
			OutputStream out = null;
			copyFile.createNewFile();
			out = new FileOutputStream(copyFile);
			
			if (resize.compress(CompressFormat.JPEG, 100, out))
			{
				out.flush();
				out.close();
			}
		}
	}
}

저작자 표시 비영리 변경 금지
신고
Posted by 쎄미

댓글을 달아 주세요



티스토리 툴바