Friday, 5 October 2012

Loading Remote JPG images in Android - Appcelerator Titanium


When I trying to Load the set of JPG images from json data (remote Images) the following error occurred.

Bitmap bounds could not be determined. If bitmap is loaded, it won't be scaled.
but its working fine in iOS. I started the research in INTERNET to fix this problem. Two solutions suggested by most of the people. They are,

1. Disabled FastDev in Android
2. Increase the VM Heap memory size.

but These are not solve my Problem. Finally I found one alternate solution for loading Remote JPG images in Android.

I am creating ImageLoader.js file for loading images....


exports.LoadRemoteImage = function (obj,url) {
   var xhr = Titanium.Network.createHTTPClient();

xhr.onload = function()
{'image data='+this.responseData);
// open the client'GET',url);

// send the data

For using this you need to pass imageView object and RemoteImageUrl.


var ImageLoader = require('ImageLoader');
var self = Ti.UI.createWindow({
  navBarHidden: true,
for(var i=0;i<5;i++) 
var fullImage = Titanium.UI.createImageView({
    left: 10,
    top : 10,
    width : 100,
    height: 100,
   self.add (fullImage);

Finally my problem is solved..... Now Remote JPG Images Loaded fine in android...

I was created Thumbnail album and FullView album by using this ImageLoader.js

But You cannot pass any other object and can not set as backgroundImage. because when you are trying to load Image through HTTPClient, the image return as blob object. In iOS backgroundImage propert supports blob but not in Android.