Note that there are some explanatory texts on larger screens.

plurals
  1. POHow resize image from gallery?
    primarykey
    data
    text
    <p>The first file allow the user to pick a photo from the gallery and sends it to an activity which will process it. The problem is that the image is too large for the phone's screen, so you only see the top corner of the image(as if it has been magnified).</p> <pre><code>Button useGallery = (Button)findViewById(R.id.loadfromgallery); useGallery.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, SELECT_PHOTO); }}) ; @Override protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { super.onActivityResult(requestCode, resultCode, imageReturnedIntent); switch(requestCode) { case SELECT_PHOTO: if(resultCode == RESULT_OK){ Uri selectedImage = imageReturnedIntent.getData(); InputStream imageStream = null; try { imageStream = getContentResolver().openInputStream(selectedImage); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream); Intent intent = new Intent(mContext, DisplayUndistortedBitmapFromGalleryActivity.class); intent.setData(selectedImage); startActivity(intent); if(yourSelectedImage != null){ Log.e(TAG,"pic ok"); }else{ Log.e(TAG,"pic not ok"); } } } </code></pre> <p>. The 2nd file is the activity that recieves the image data from the intent and places it in a URI that a bitmap is the derived from.</p> <pre><code>public class DisplayUndistortedBitmapFromGalleryActivity extends Activity { private static final String TAG = "*********DUBFGActivity"; private Context mContext = this; Uri uri; private Bitmap mbitmap = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); uri = getIntent().getData(); if(uri != null){ Log.e(TAG, "uri ok"); }else { Log.e(TAG, "uri not ok"); } try { mbitmap = Media.getBitmap(getContentResolver(), uri); //setMbitmap(bitmap); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } </code></pre> <p>.</p> <p>I have a 3rd file which is the customview for the activity. The line below retrieves the bitmap from it's activity and displays it. Is there a way of downsizing the bitmap so it fits on the screen? thanks.</p> <pre><code>Bitmap bm = ((DisplayUndistortedBitmapFromGalleryActivity)getContext()).getMbitmap(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload