makeImageRequst on a 4.0 device

Now that we have a sample 4.0 device to play with, I decided to see how the new graphics/bitmap handling will affect my widget.  It appears that I am going to need to make some changes to how I handle receiving bitmaps through the makeImageRequest function.

On existing devices I check that the data is actually a bitmap resource.  If it is, I save it to a class variable (bitmap) which I then display on the screen with the next onUpdate.  What I am seeing is the data does not pass the instanceof check for BitmapResource on the 4.0 device.  Below is my call back method being used.

function onReceiveImage(responseCode, data) {
    System.println("view fctn recieveimg");
	if(responseCode==200) {
		if(data instanceof Ui.BitmapResource) {
			System.println("IMAGE OK");
			bitmap = data;
			Ui.requestUpdate();
		} else {
			System.println("IMAGE NOT OK");
		}
	} else {
		data = null;
		System.println("imgstatus="+DisplayError);
		Ui.requestUpdate();
	}
}
 

On the 3.x and below devices, the Image Ok will print and the bitmap will display.  On the 4.0 sample device, I get Image Not Ok, thus the bitmap is not set.  The makeImageRequest documentation says that the callback should expect two inputs and the data should be a BitmapResource or null.  

responseCallback as Method(responseCode as Number, data as BitmapResource or Null)

My question is because of the new graphics pool, do I need to wrap the data in the new createBufferedBitmap method to save the downloaded resource for display?

  • Great feedback.--I'll pass it on to the team. Slight smile That's exactly the kind of benefit we're hoping developers will see.

  • The size of the pool will vary by device, and the amount of space available will depend on what the system is using and has locked in the pool.

    If you download an image and you don't want it to be purged from the pool when another resource is loaded, you need to use the ResourceReference.get() method to get a handle to the resource and then hold that. If you want to allow your resource to be purged, you'd want to keep the ResourceReference and then check the result of get() to see if it is still available. If not you'd either need to re-download the image or read it back from storage (assuming you wrote it to Storage after downloading).