Advertisement
Guest User

MainActivit_start

a guest
Dec 5th, 2012
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 KB | None | 0 0
  1.  
  2. public class Main1 extends Activity{
  3. private Button mGellery,mCamera;
  4. private static final int RESULT_LOAD_IMAGE = 1;
  5. public static Bitmap mBitMap;
  6. String TAG = "Main1";
  7. int IMAGE_MAX_SIZE = 320;
  8. @Override
  9. protected void onCreate(Bundle savedInstanceState) {
  10. // TODO Auto-generated method stub
  11. super.onCreate(savedInstanceState);
  12. setContentView(R.layout.m);
  13.  
  14. mGellery=(Button)findViewById(R.id.button1);
  15. mGellery.setOnClickListener(new OnClickListener() {
  16.  
  17. @Override
  18. public void onClick(View arg0) {
  19. // TODO Auto-generated method stub
  20. Intent i = new Intent(
  21. Intent.ACTION_PICK,
  22. android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  23.  
  24. startActivityForResult(i, RESULT_LOAD_IMAGE);
  25.  
  26.  
  27. }
  28. });
  29. mCamera=(Button)findViewById(R.id.button2);
  30. mCamera.setOnClickListener(new OnClickListener() {
  31.  
  32. @Override
  33. public void onClick(View arg0) {
  34. // TODO Auto-generated method stub
  35. Intent i = new Intent(Main1.this,PhotoMargingActivity.class);
  36. i.putExtra("image", false);
  37. startActivity(i);
  38. }
  39. });
  40. }
  41.  
  42.  
  43.  
  44.  
  45.  
  46. @Override
  47. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  48. super.onActivityResult(requestCode, resultCode, data);
  49.  
  50. if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
  51. Uri selectedImage = data.getData();
  52. String[] filePathColumn = { MediaStore.Images.Media.DATA };
  53.  
  54. Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
  55. cursor.moveToFirst();
  56.  
  57. int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
  58. String picturePath = cursor.getString(columnIndex);
  59. cursor.close();
  60.  
  61. //............... to get the decode file .........................................
  62.  
  63. mBitMap = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(picturePath),250, 250, true);
  64. // mBitMap = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(picturePath),250, 250, true);
  65.  
  66. // mPicture = new ImageView(context);
  67. // mPicture.setImageBitmap(bm);
  68. // mBitMap=BitmapFactory.decodeFile(picturePath);
  69. // mImage.setImageBitmap();
  70. Intent i = new Intent(Main1.this,PhotoMargingActivity.class);
  71. i.putExtra("image", true);
  72. startActivity(i);
  73. }
  74.  
  75. }
  76. // private Bitmap decodeFile(File f){
  77. // try {
  78. // //Decode image size
  79. // BitmapFactory.Options o = new BitmapFactory.Options();
  80. // o.inJustDecodeBounds = true;
  81. // BitmapFactory.decodeStream(new FileInputStream(f),null,o);
  82. //
  83. // //The new size we want to scale to
  84. // final int REQUIRED_SIZE=70;
  85. //
  86. // //Find the correct scale value. It should be the power of 2.
  87. // int scale=1;
  88. // while(o.outWidth/scale/2>=REQUIRED_SIZE && o.outHeight/scale/2>=REQUIRED_SIZE)
  89. // scale*=2;
  90. //
  91. // //Decode with inSampleSize
  92. // BitmapFactory.Options o2 = new BitmapFactory.Options();
  93. // o2.inSampleSize=scale;
  94. // return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
  95. // } catch (FileNotFoundException e) {}
  96. // return null;
  97. // }
  98. private Bitmap decodeFile(File f){
  99. Bitmap b = null;
  100. try {
  101. //Decode image size
  102. BitmapFactory.Options o = new BitmapFactory.Options();
  103. o.inJustDecodeBounds = true;
  104. o.inSampleSize = 8;
  105.  
  106. FileInputStream fis = new FileInputStream(f);
  107. BitmapFactory.decodeStream(fis, null, o);
  108. fis.close();
  109.  
  110. int scale = 1;
  111. if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) {
  112. scale = (int)Math.pow(2, (int) Math.round(Math.log(IMAGE_MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
  113. }
  114.  
  115. //Decode with inSampleSize
  116. BitmapFactory.Options o2 = new BitmapFactory.Options();
  117. o2.inSampleSize = scale;
  118. fis = new FileInputStream(f);
  119. b = BitmapFactory.decodeStream(fis, null, o2);
  120. fis.close();
  121. } catch (IOException e) {
  122. }
  123. return b;
  124. }
  125. }
  126. here is another
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement