Return-Path: X-Original-To: apmail-incubator-callback-dev-archive@minotaur.apache.org Delivered-To: apmail-incubator-callback-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A1BD5949A for ; Tue, 8 Nov 2011 07:35:23 +0000 (UTC) Received: (qmail 63580 invoked by uid 500); 8 Nov 2011 07:35:23 -0000 Delivered-To: apmail-incubator-callback-dev-archive@incubator.apache.org Received: (qmail 63476 invoked by uid 500); 8 Nov 2011 07:35:21 -0000 Mailing-List: contact callback-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@incubator.apache.org Delivered-To: mailing list callback-dev@incubator.apache.org Received: (qmail 62634 invoked by uid 99); 8 Nov 2011 07:35:17 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Nov 2011 07:35:17 +0000 X-ASF-Spam-Status: No, hits=-2001.2 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Nov 2011 07:35:14 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 9E8A03D23D for ; Tue, 8 Nov 2011 07:34:53 +0000 (UTC) Date: Tue, 8 Nov 2011 07:34:53 +0000 (UTC) From: "Bright Zheng (Created) (JIRA)" To: callback-dev@incubator.apache.org Message-ID: <1160906738.9940.1320737693650.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Created] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions --------------------------------------------------------------------------------------------- Key: CB-14 URL: https://issues.apache.org/jira/browse/CB-14 Project: Apache Callback Issue Type: Improvement Components: Android Affects Versions: 1.1.0 Environment: Android SDK: 2.x & above JDK: 1.6 Eclipse: Helios Reporter: Bright Zheng Priority: Critical Fix For: 2.0.0 Currently the CameraLauncher plugin of Phonegap (or Apache Callback) is using Android default API for stream decoding. It will be very easy to get crash by throwing out the OutOfMemory exceptions while loading bigger image files. So I add a new method called safeDecodeStream for better stream decoding. {code:title=safeDecodeStream method|borderStyle=solid} /** * A safer decodeStream method * rather than the one of {@link BitmapFactory} * which will be easy to get OutOfMemory Exception * while loading a big image file. * * @param uri * @param width * @param height * @return * @throws FileNotFoundException */ protected Bitmap safeDecodeStream(Uri uri, int width, int height) throws FileNotFoundException{ int scale = 1; BitmapFactory.Options options = new BitmapFactory.Options(); android.content.ContentResolver resolver = this.ctx.getContentResolver(); if(width>0 || height>0){ // Decode image size without loading all data into memory options.inJustDecodeBounds = true; BitmapFactory.decodeStream( new BufferedInputStream(resolver.openInputStream(uri), 16*1024), null, options); int w = options.outWidth; int h = options.outHeight; while (true) { if ((width>0 && w/2 < width) || (height>0 && h/2 < height)){ break; } w /= 2; h /= 2; scale *= 2; } } // Decode with inSampleSize option options.inJustDecodeBounds = false; options.inSampleSize = scale; return BitmapFactory.decodeStream( new BufferedInputStream(resolver.openInputStream(uri), 16*1024), null, options); } {code} And then change all the codes which are invoking the Android decodeStream API directly to this method. e.g. {code:title=usage example|borderStyle=solid} //Updated by Bright for safer decodeStream //android.content.ContentResolver resolver = this.ctx.getContentResolver(); //bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri)); bitmap = safeDecodeStream(uri, this.targetWidth, this.targetHeight); {code} -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira