Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main1 extends Activity{
- private Button mGellery,mCamera;
- private static final int RESULT_LOAD_IMAGE = 1;
- public static Bitmap mBitMap;
- String TAG = "Main1";
- int IMAGE_MAX_SIZE = 320;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- setContentView(R.layout.m);
- mGellery=(Button)findViewById(R.id.button1);
- mGellery.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- // TODO Auto-generated method stub
- Intent i = new Intent(
- Intent.ACTION_PICK,
- android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
- startActivityForResult(i, RESULT_LOAD_IMAGE);
- }
- });
- mCamera=(Button)findViewById(R.id.button2);
- mCamera.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- // TODO Auto-generated method stub
- Intent i = new Intent(Main1.this,PhotoMargingActivity.class);
- i.putExtra("image", false);
- startActivity(i);
- }
- });
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
- Uri selectedImage = data.getData();
- String[] filePathColumn = { MediaStore.Images.Media.DATA };
- Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
- cursor.moveToFirst();
- int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
- String picturePath = cursor.getString(columnIndex);
- cursor.close();
- //............... to get the decode file .........................................
- mBitMap = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(picturePath),250, 250, true);
- // mBitMap = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(picturePath),250, 250, true);
- // mPicture = new ImageView(context);
- // mPicture.setImageBitmap(bm);
- // mBitMap=BitmapFactory.decodeFile(picturePath);
- // mImage.setImageBitmap();
- Intent i = new Intent(Main1.this,PhotoMargingActivity.class);
- i.putExtra("image", true);
- startActivity(i);
- }
- }
- // private Bitmap decodeFile(File f){
- // try {
- // //Decode image size
- // BitmapFactory.Options o = new BitmapFactory.Options();
- // o.inJustDecodeBounds = true;
- // BitmapFactory.decodeStream(new FileInputStream(f),null,o);
- //
- // //The new size we want to scale to
- // final int REQUIRED_SIZE=70;
- //
- // //Find the correct scale value. It should be the power of 2.
- // int scale=1;
- // while(o.outWidth/scale/2>=REQUIRED_SIZE && o.outHeight/scale/2>=REQUIRED_SIZE)
- // scale*=2;
- //
- // //Decode with inSampleSize
- // BitmapFactory.Options o2 = new BitmapFactory.Options();
- // o2.inSampleSize=scale;
- // return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
- // } catch (FileNotFoundException e) {}
- // return null;
- // }
- private Bitmap decodeFile(File f){
- Bitmap b = null;
- try {
- //Decode image size
- BitmapFactory.Options o = new BitmapFactory.Options();
- o.inJustDecodeBounds = true;
- o.inSampleSize = 8;
- FileInputStream fis = new FileInputStream(f);
- BitmapFactory.decodeStream(fis, null, o);
- fis.close();
- int scale = 1;
- if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) {
- scale = (int)Math.pow(2, (int) Math.round(Math.log(IMAGE_MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
- }
- //Decode with inSampleSize
- BitmapFactory.Options o2 = new BitmapFactory.Options();
- o2.inSampleSize = scale;
- fis = new FileInputStream(f);
- b = BitmapFactory.decodeStream(fis, null, o2);
- fis.close();
- } catch (IOException e) {
- }
- return b;
- }
- }
- here is another
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement