Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
greno
Visitor

Can't create roBitmap from downloaded image

I'm trying to create a roBitmap from a downloaded image file, but it isn't working. Here's the code snippet:


sTempFile = "tmp:/temp.jpg"

UT=CreateObject("roUrlTransfer")
UT.SetUrl(sUrl)
iResult = UT.GetToFile(sTempFile)
print "Download status code: "; iResult

if (FileExists(sTempFile) = true) then
print "Downloaded media file exists"
else
print "Downloaded media file does NOT exist"
end if

img1 = CreateObject("roBitmap", sTempFile)
if (img1 = Invalid) then
print "roBitmap Invalid!"
end if

'Does file exist
Function FileExists(file as String) as Integer
fs = CreateObject("roFileSystem")
If fs.Exists(file) Then
stats = fs.Stat(file)
print "Type = ";stats.type;", size="; stats.size
return 1
End If
return 0
end function



And here is the result:


Download status code: 200
Type = file, size= 2994370
Downloaded media file exists
roBitmap Invalid!


Any idea on why this doesn't work? Or is there an error code somewhere I can check for more detail?

BTW, I'll switch to the async version once I get this working.

Thanks
0 Kudos
14 REPLIES 14
NewManLiving
Visitor

Re: Can't create roBitmap from downloaded image

what is the actual size of your image. Your file size is rather large
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos
greno
Visitor

Re: Can't create roBitmap from downloaded image

That looks like the right size to me. It's a 3 meg photo from an Android phone. It displays OK in roSlideShow.
0 Kudos
squirreltown
Roku Guru

Re: Can't create roBitmap from downloaded image

"greno" wrote:
That looks like the right size to me. It's a 3 meg photo from an Android phone. It displays OK in roSlideShow.


RoSlideshow uses some mechanism to scale the pictures down. If your original pic is bigger than 2048 in either direction ( very likely from a current smartphone) it wont get bitmap'd.
Kinetics Screensavers
0 Kudos
greno
Visitor

Re: Can't create roBitmap from downloaded image

What I'm trying to do is download the picture, then scale and possibly rotate it (since roSlideShow doesn't know how to do with rotation info in EXIF). In order to manipulate it, I figured I need to create a bitmap first, then use regions to manipulate it. Is there a better way?

I'm just trying to do a simple slideshow function with one image displayed at a time, as large as possible, with the correct orientation. I know if I rotate it I'm going to have to do the math to scale and position it. If you know of any samples that do this, let me know. I haven't been able to find any.

-Gregg
0 Kudos
NewManLiving
Visitor

Re: Can't create roBitmap from downloaded image

There are limitations to the size of the bitmap and to the amount of memory the device has. These two reasons also contribute to an Invalid bitmap. roSlideshow does it's own thing. If you are manually loading a bitmap then you need to follow the guidelines set forth in the documentation and be aware of available memory to load your large bitmaps (not size of file, but height and width of bitmap) . You may be able to do something with the texturemanager and then allow it to scale for you before you rotate it. Don't know, I use the texturemanager a lot but not on anything that size. But I would try it to see what happens
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos
greno
Visitor

Re: Can't create roBitmap from downloaded image

Thanks, I'll give it a try. If that doesn't work I'll just give up on this enhancement. I requested that roSlideShow take the EXIF rotation into account a couple of years ago but nothing was done.
0 Kudos
squirreltown
Roku Guru

Re: Can't create roBitmap from downloaded image

The textureManager can deal with pictures bigger then 2048, you just have to request the image at 2048 or less, and no reason to make it bigger than 1280x720 since thats how it displays it. The only problem is the texmgr doesn't do ratios or size- to-fill or any of that , you have to request a specific size, so you would download the image to tmp: then run your metadata on it and get then request the proper size. If you are using roSlideshow you would probably need to draw-rotated the pics that need rotation into a second bitmap and use that since there is ( as you noticed) still no rotation feature in the slideshow.
Kinetics Screensavers
0 Kudos
greno
Visitor

Re: Can't create roBitmap from downloaded image

OK, thanks for the advice. I did a quick test with texturemanager to download the image using the screen dimensions, got the bitmap from that and displayed it on an roScreen, and it worked. However, waiting for the request took 11 seconds over a LAN, so it's looking like it's a lot slower than roSlideshow. But I'll have to do more performance tests. I'll also try downloading it locally and then using texturemanager to see if there is any difference. Once I have that bitmap, i'll use the scale and rotate functions

Thanks,
-Gregg
0 Kudos
NewManLiving
Visitor

Re: Can't create roBitmap from downloaded image

I don't know what the slideshow is using. If not the texturemanager then whatever it is I would like to have access to it. The thing with the texturemanager in my experience is that 'generally' the more you asynchronously request during one transaction, is faster than polling for one image to return or using the synchronous method. It does have some type of LRU ( at least it appears that way ) so the next time is faster. You have to tweak it yourself. If you can, it probably would be better to reduce the file size to something smaller. I convert to jpg whenever possible since (most of the time) it is a much smaller file size than png. Or if it does have transparency in it I may create a layer with the background underneath (if the background is static) and then convert to jpg. Squirreltown has far more experience with larger bitmaps and the texturemanager. Perhaps he can offer further insight
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos