Monday, April 30, 2012

Re: [android-developers] Fitting image to a screen



 Code:
 I have this code in the Activity result, when the user hits load, it will open the gallery allow him to choose a picture. The selected pictured is passed to another activity, here is where i'm facing the problem. The picture doesn't fit the screen.
     
                        
                Uri selectedimage= data.getData();

         Uri contentUri = data.getData();          

             String[] proj = { MediaStore.Images.Media.DATA };         

             Cursor cursor = managedQuery(contentUri, proj, null, null, null);         

             int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);         

             cursor.moveToFirst();         

             String tmppath = cursor.getString(column_index);

             

         Intent intent= new Intent(this,NasalProjectionActivity.class);

         intent.putExtra("imagePath",tmppath);

           startActivity(intent);  


 Receiving Activity,

 Thats what i have on the receiving activity.

    

     Bitmap b = BitmapFactory.decodeFile(getIntent().getStringExtra("imagePath"));

        int newHe=750;

        int newWe=750;

       


        int width=b.getWidth();

        int height = b.getHeight();

        float scaleWidth = ((float) newWe) / width;

        float scaleHeight = ((float) newHe) / height;

        Matrix matrix = new Matrix();

        matrix.postScale(scaleWidth, scaleHeight);

        Bitmap resizedBitmap = Bitmap.createBitmap(b, 0, 0, width, height, matrix, false);         


Thanks alot

On Mon, Apr 30, 2012 at 7:51 PM, Justin Anderson <magouyaware@gmail.com> wrote:
What have you tried so far?  How are you loading the image?

Thanks,
Justin Anderson
MagouyaWare Developer
http://sites.google.com/site/magouyaware



On Mon, Apr 30, 2012 at 1:55 AM, Mohamed ElSanousi <mmurtada57@gmail.com> wrote:
Hi!!

 I'm trying to load a picture from the gallery and display, everything
works fine except that the returned image is stretched and doesn't fit
the mobile screen size? I need help, thanks alot :)

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment