Re: [android-developers] Re: Where in code would i resize an image taken using intent?
Daniel, In my case, the large image is read from storage resized then saved to storage. Dave Truby On Apr 12, 2015 12:37 AM, "Daniel Chacon" wrote: > So what you are doing is resizing before or after being saved or uploaded? > > On Sat, Apr 11, 2015 at 6:59 AM, Dave Truby wrote: > >> Dan, >> >> I am doing the following in my Over Time app. Maybe it helps you. >> >> >> File aThumbnail = new File(pDir, TbsFile.THUMBNAIL_FILENAME); >> >> final float aRatio = (float) pPictureWidth / (float) pPictureHeight; >> >> final int aThumbnailWidth = Math.round(pThumbnailHeight * aRatio); >> >> final BitmapFactory.Options anOptions = new BitmapFactory.Options(); >> >> anOptions.inJustDecodeBounds = false; >> >> anOptions.inSampleSize = this.calculateInSampleSize(pPictureWidth, >> pPictureHeight, aThumbnailWidth, pThumbnailHeight); >> >> Bitmap aBitmap = >> BitmapFactory.decodeFile(pImageToMakeThumbnail.getAbsolutePath(), >> anOptions); >> >> Bitmap aScaledBitmap = Bitmap.createScaledBitmap(aBitmap, >> aThumbnailWidth, pThumbnailHeight, true); >> >> this.saveThumbnail(pContext, aThumbnail, aScaledBitmap); >> >>aScaledBitmap.recycle(); >> >> } >> >> private int calculateInSampleSize(final int pPictureWidth, final int >> pPictureHeight, >> >> final int pThumbnailWidth, final int pThumbnailHeight) { >> >> int aInSampleSize = 1; >> >> if (pPictureHeight > pThumbnailHeight || pPictureWidth > >> pThumbnailWidth) { >> >> final int aHeightRatio = Math.round((float) pPictureHeight / (float) >> pThumbnailHeight); >> >> final int aWidthRatio = Math.round((float) pPictureWidth / (float) >> pThumbnailWidth); >> >> aInSampleSize = aHeightRatio < aWidthRatio ? aHeightRatio : aWidthRatio; >> >> } >> >> return aInSampleSize; >> >> } >> >> private void saveThumbnail(final Context pContext, final File >> pThumbnail, final Bitmap pScaledBitmap) { >> >> boolean isCreated = false; >> >> FileOutputStream anOutputStream = null; >> >> try { >> >> anOutputStream = new FileOutputStream(pThumbnail); >> >> pScaledBitmap.compress(Bitmap.CompressFormat.JPEG, >> >> TbsCreateThumbnailAsyncTask.JPEG_COMPRESSION, anOutputStream); >> >> isCreated = true; >> >> } catch (IOException anIoEx) { >> >> this.error("saveThumbnail()", anIoEx); >> >> } catch (Exception anEx) { >> >> this.error("saveThumbnail()", anEx); >> >> } finally { >> >> if (null != anOutputStream) { >> >> try { >> >> anOutputStream.close(); >> >> } catch (IOException e) { >> >> // nothing >> >> } >> >> } >> >> if (isCreated) { >> >> MediaScannerConnection.scanFile(pContext, >> >>new String[] { pThumbnail.getAbsolutePath() }, null, >> >>new MediaScannerConnection.OnScanCompletedListener() { >> >>@Override >> >>public void onScanCompleted(final String pPath, final Uri pUri) { >> >> TbsCreateThumbnailAsyncTask.this.info("onScanCompleted()", "Scanned >> thumbnail " + pPath + TbsLog.PERIOD); >> >>} >> >>}); >> >> } >> >> } >> >> } >> >> >> On Friday, April 10, 2015 at 5:27:42 PM UTC-4, Dan Cha wrote: >>> >>> So ive been reading a few posts some using Bitmap.createScaledBitmap, >>> some using .compress feature and each one i try, never throws an exception >>> or error, but file never gets resized. >>> >>> I found this routine, but it doesnt do anything as far as the image >>> taken. So basically within my app i allow the user to take a pic to attach >>> to the submission. >>> When you take the image, it displays a thumbnail on the screen, at this >>> point the image is already saved to the phones gallery. >>> I need to resize it (without changing the proportions) to make sure that >>> the image is no larger than 200px wide or high because once you submit the >>> form, im uploading the image to our server. >>> >>> public Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) { >>> int width = bm.getWidth(); >>> int height = bm.getHeight(); >>> float scaleWidth = ((float) newWidth) / width; >>> float scaleHeight = ((float) newHei
[android-developers] Re: Where in code would i resize an image taken using intent?
Dan, I am doing the following in my Over Time app. Maybe it helps you. File aThumbnail = new File(pDir, TbsFile.THUMBNAIL_FILENAME); final float aRatio = (float) pPictureWidth / (float) pPictureHeight; final int aThumbnailWidth = Math.round(pThumbnailHeight * aRatio); final BitmapFactory.Options anOptions = new BitmapFactory.Options(); anOptions.inJustDecodeBounds = false; anOptions.inSampleSize = this.calculateInSampleSize(pPictureWidth, pPictureHeight, aThumbnailWidth, pThumbnailHeight); Bitmap aBitmap = BitmapFactory.decodeFile(pImageToMakeThumbnail.getAbsolutePath(), anOptions); Bitmap aScaledBitmap = Bitmap.createScaledBitmap(aBitmap, aThumbnailWidth, pThumbnailHeight, true); this.saveThumbnail(pContext, aThumbnail, aScaledBitmap); aScaledBitmap.recycle(); } private int calculateInSampleSize(final int pPictureWidth, final int pPictureHeight, final int pThumbnailWidth, final int pThumbnailHeight) { int aInSampleSize = 1; if (pPictureHeight > pThumbnailHeight || pPictureWidth > pThumbnailWidth) { final int aHeightRatio = Math.round((float) pPictureHeight / (float) pThumbnailHeight); final int aWidthRatio = Math.round((float) pPictureWidth / (float) pThumbnailWidth); aInSampleSize = aHeightRatio < aWidthRatio ? aHeightRatio : aWidthRatio; } return aInSampleSize; } private void saveThumbnail(final Context pContext, final File pThumbnail, final Bitmap pScaledBitmap) { boolean isCreated = false; FileOutputStream anOutputStream = null; try { anOutputStream = new FileOutputStream(pThumbnail); pScaledBitmap.compress(Bitmap.CompressFormat.JPEG, TbsCreateThumbnailAsyncTask.JPEG_COMPRESSION, anOutputStream); isCreated = true; } catch (IOException anIoEx) { this.error("saveThumbnail()", anIoEx); } catch (Exception anEx) { this.error("saveThumbnail()", anEx); } finally { if (null != anOutputStream) { try { anOutputStream.close(); } catch (IOException e) { // nothing } } if (isCreated) { MediaScannerConnection.scanFile(pContext, new String[] { pThumbnail.getAbsolutePath() }, null, new MediaScannerConnection.OnScanCompletedListener() { @Override public void onScanCompleted(final String pPath, final Uri pUri) { TbsCreateThumbnailAsyncTask.this.info("onScanCompleted()", "Scanned thumbnail " + pPath + TbsLog.PERIOD); } }); } } } On Friday, April 10, 2015 at 5:27:42 PM UTC-4, Dan Cha wrote: > > So ive been reading a few posts some using Bitmap.createScaledBitmap, some > using .compress feature and each one i try, never throws an exception or > error, but file never gets resized. > > I found this routine, but it doesnt do anything as far as the image taken. > So basically within my app i allow the user to take a pic to attach to the > submission. > When you take the image, it displays a thumbnail on the screen, at this > point the image is already saved to the phones gallery. > I need to resize it (without changing the proportions) to make sure that > the image is no larger than 200px wide or high because once you submit the > form, im uploading the image to our server. > > public Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) { > int width = bm.getWidth(); > int height = bm.getHeight(); > float scaleWidth = ((float) newWidth) / width; > float scaleHeight = ((float) newHeight) / height; > // CREATE A MATRIX FOR THE MANIPULATION > Matrix matrix = new Matrix(); > // RESIZE THE BIT MAP > matrix.postScale(scaleWidth, scaleHeight); > > // "RECREATE" THE NEW BITMAP > Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, > matrix, false); > return resizedBitmap;} > > > When the user clicks the image button on the screen, the camera opens and > allows them to take the pic, ive tried to call the above routine within this > event after everything so that i know the file is created and exists. > > > Here is the event for that: > > private ImageButton.OnClickListener takePicture_Button_listener = new > ImageButton.OnClickListener() > { > public void onClick(View v) > { > StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() > .detectDiskReads() > .detectDiskWrites() > .detectNetwork() > .penaltyLog() > .build()); > // create Intent to take a picture and return control to the > calling application > Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); > > //User fileUri for full path to image taken. > fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a > file to save the image > fname = > fileUri.toString().substring(fileUri.toString().lastIndexOf("/")+1); > intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the > image file name > > // start the image capture
[android-developers] Bluetooth devices connected list - getConnectedDevices()
This call is for bluetooth low energy connections. Are you sure you have a low energy device connected? It looks like you are connecting a mouse, I'm not sure that is a low energy device. -- 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+unsubscr...@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 unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[android-developers] Re: Cannot get the initial SDK setup working, nightmare
Using the AVD tool (inside Eclipse, menu "Window" -> "Android Virtual Device Manager"), create at least one virtual device. See http://developer.android.com/tools/devices/index.html After you have a virtual device created, start it by selecting it in the list (in AVD manager) then click the "Start" button. Note: depending on your computer, it may take a while for the emulator to start. After you see the emulator window and the android virtual device is fully booted, click around to see how it works (it is slightly different than a real device). With the emulator running, right click on your android project and select "Run as" -> "Android application". You may be asked to select a device (pick the AVD you just created). I find it easier to run my android project on my phone (connected via usb). See http://developer.android.com/tools/device.html On Sunday, March 31, 2013 7:46:15 AM UTC-4, NewToAndroid wrote: > > Hi All, > > I am on a Windows Vista (32 bit) laptop, using Java version 1.6.0_29. I > downloaded the "Android SDK ADT Bundle" from developer.android.com. I am > under impression that, I need not do any other setup/installation when I am > using the bundle. Using a Windows account which is administrator. Created > the basic "Hallo World App" which is shown here " > http://developer.android.com/training/basics/firstapp/creating-project.html"; > . Now trying to run it on emulator, which is proving to be a nightmare (so > much so that, I am on the verge of giving up learning Android development). > 1) When I run the application, should the emulator be already running? or > Eclipse will start it? > 2) When I click on "Run -> Run" or "Run -> Run as -> Android Application", > nothing happens, no prompts, no messages on console, nothing. I am not sure > if I should wait for something to happen or there is something missing? > 3) Emulator is already running. Clicked on Run -> Run. Nothing happened > > Are there any configurations, parameters, which need to be done before I > try to run the project? > > Thanks in advance > > -- -- 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+unsubscr...@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 unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[android-developers] Re: Error in the "Interacting with other apps" class on developer.android.com
In the link you provided I see the Uri.parse() syntax. On Saturday, March 30, 2013 4:09:03 PM UTC-4, Mateusz Matlengiewicz wrote: > > Hi, > > I'm new to Android app developement so forgive me if what I write is > untrue. > I was looking throu the starting classes and in > http://developer.android.com/training/basics/intents/result.html#StartActivityI > found this line of code: > > > Intent pickContactIntent = new Intent(Intent.ACTION_PICK, new > Uri("content://contacts")); > > My Eclipse IDE is showing me an error with the Uri class, after some > searching I managed to get it working with > > Intent pickContactIntent = new Intent(Intent.ACTION_PICK, > Uri.parse("content://contacts")); > > Now my question is am I doing something wrong or is it really an error in the > tutorial? > > Sincerly, > MM > > > -- -- 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+unsubscr...@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 unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[android-developers] Re: App ran at startup
You can have an activity started at boot by doing the following: public class BootReceiver extends BroadcastReceiver { public void onReceive(Context context) { context.startActivity(new Intent(context, SomeActivity.class)); } } On Saturday, March 23, 2013 6:22:44 PM UTC-4, J4ckkn1fe wrote: Is there anyway to make an app run at startup and open a locked browser, > user cannot minimize it or close. The said phone would not have any other > apps everything would be run through the website. Also the phone > wouldn't receive calls. You can compare the functionality I want to achieve > to that of the itouch. Except everything would be ran through a website. Is > this possible with android if I heavily modded it? -- -- 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+unsubscr...@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 unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[android-developers] Re: How to dynamically add new ImageView instances to RelativeLayout?
You are setting the id in tiles[i].setId(i); Also, titles[i] does not appear to have any children, so why tiles[i].findViewById() I'm probably not seeing what you are trying to do. On Sunday, March 31, 2013 6:10:00 AM UTC-4, langui...@gmail.com wrote: > > What I am trying to do is create *N* (in this case 9) copies of the > ImageView object R.id.tile, place each of them at different coordinates > on the layout, and give each its own individual identifier. > > *BoardLayout.class:* > > @Overrideprotected void onCreate(Bundle savedInstance){ > super.onCreate(savedInstance); > setContentView(R.layout.board_layout); > entire_layout = (RelativeLayout)findViewById(R.layout.board_layout); > inner_layout = (RelativeLayout)findViewById(R.id.board); > View[] tiles = new ImageView[9]; > > > for(int i = 0; i tiles[i] = (ImageView)findViewById(R.id.tile); > tiles[i].setId(i); > params = new RelativeLayout.LayoutParams(-1, 345); > params.leftMargin = 32*2*3; > params.topMargin = 34*2*3; > layout.addView(tiles[i].findViewById(R.id.tile)); > } > ... > > > *board_layout.xml:* > > xmlns:android="http://schemas.android.com/apk/res/android"; > android:layout_width="fill_parent" > android:layout_height="fill_parent" > android:background="@drawable/backgroundcolor" > android:orientation="vertical" > > > android:id="@+id/topbar" > ... > > > android:id="@+id/imagebutton" > ... /> > > > > android:id="@+id/board" > android:layout_width="match_parent" > android:layout_height="345dp" > android:layout_centerVertical="true" > android:background="@drawable/wwfboard" > > > android:id="@+id/myView" > android:layout_width="fill_parent" > android:layout_height="fill_parent" /> > > android:id="@+id/tile" > android:layout_width="21dp" > android:layout_height="21dp" > android:src="@drawable/tile" /> > > > > However, I keep getting the *"Source not found"* error on the last line: > layout.addView(tiles[i].findViewById(R.id.tile));.. > > Any ideas why? > > (Side question: is RelativeLayout better than AbsoluteLayout for working > with coordinates?) > > -- -- 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+unsubscr...@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 unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.