Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-26456

Android: Optimize TiBlob.imageAsResized

    Details

    • Story Points:
      3
    • Sprint:
      2019 Sprint 3, 2019 Sprint 4, 2019 Sprint 5, 2019 Sprint 6, 2019 Sprint 7, 2019 Sprint 8, 2019 Sprint 9

      Description

      I had a look at the implementation of TiBlob.imagesAsResized on Android and it could be optimized according to this stackoverflow article: https://stackoverflow.com/a/32121059/5193915

      Rather than opening the image using getImage() and then creating a new Bitmap with createScaledBitmap() to resize it the rescaled image could be opened right away (with inTargetDensity + inDensity).

      In my test patch I've returned the getImage() Bitmap right away when rotation is 0. According to it will save some memory.

      But I'm not 100% sure what mMemoryCache will do so I need some help/guidance if that is still needed. It was added in https://jira.appcelerator.org/browse/TIMOB-16450 to solve some memory leak.

      Test code:

      _.delay(function() {
      	Titanium.Media.showCamera({
      		success: function(e) {
      			var start = new Date().getTime();
      			var blob = e.media;
      			var w = e.media.width;
      			var h = e.media.height;
      			var r = h / w;
      			w = 300;
      			h = r * w;
      			blob = blob.imageAsResized(w, h);
      			$.img.image = blob;
      			var end = new Date().getTime();
      			console.log(end - start);
      		},
      		cancel: function() {},
      		error: function(error) {},
      		mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO]
      	});
      }, 4000);
       
      $.index.open();
      

      <Alloy>
      	<Window class="container">
      		<ImageView id="img"></ImageView>
      	</Window>
      </Alloy>
      

        Attachments

          Activity

            People

            • Assignee:
              gmathews Gary Mathews
              Reporter:
              michael Michael Gangolf
              Tester:
              Lokesh Choudhary
            • Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-6629
                  Sync status:
                  PENDING
                  Last received:
                  Last sent:

                  Git Source Code