picking and displayed saved photos

Hi,

I have modified the widget demo to let me pick and display a photo from the photo library and is partly working but it has problems. It is probably because I am taking code from several examples. Anyway, here are the problems:

  1. I can pick the photo but it displays twice, one at the origin and the other correctly where I wanted in the thumbnail. Where is this other photo coming from.

  2. Both photos stay even though I go on to other widgets. I have tried removeself() and it gives an error on this img.

  3. I am supposed to be saving the photo in the system.DocumentsDirectory but I cannot find the file anywhere on my laptop. I really don’t need to save it but the example code I am using uses it and I can’t seem to not use it because I then get an error in the thumbnail display.

Here is the code:

local function sessionComplete ( event )  
  
 local photo = event.target  
 local baseDir = system.DocumentsDirectory  
 display.save(photo, "photo.jpg", baseDir)  
end  
  
local function newphoto ( event )  
 clearGroup( demoGroup )   
-- choose photo library for picture  
 media.show( media.SavedPhotosAlbum, sessionComplete )  
  
  
 -- create scrollView widget  
 scrollBox = widget.newScrollView{  
 --top = display.statusBarHeight + titleBar.height,  
 width = 320,  
 height = 366,  
 maskFile = "assets/wallpaper.jpg"  
 }  
  
 -- insert widget into demoGroup  
 demoGroup:insert( scrollBox.view )  
 -- Create thumbnail  
 local thumbnail = display.newGroup()  
 local baseDir = system.DocumentsDirectory  
 local img = display.newImage("photo.jpg",baseDir)  
 thumbnail:insert( img, true )  
 img:scale( 0.5, 0.5 )  
   
 local r = 5  
 local border = display.newRoundedRect( 0, 0, img.contentWidth + 2\*r, img.contentHeight + 2\*r, r )  
 border:setFillColor( 0,255,255,200 )  
 thumbnail:insert( 1, border, true )  
 thumbnail:translate( 0.5\*display.contentWidth, 0.5\*display.contentHeight )   
  
end   

And here is the display


I cannot seem to paste the image of the display. How do you paste an image here. I do a copy but can’t paste !
[import]uid: 95689 topic_id: 19141 reply_id: 319141[/import]

When I try to pick another photo, I get this error (not really an error):

Copyright (C) 2009-2011 A n s c a , I n c .  
 Version: 2.0.0  
 Build: 2011.703  
The file sandbox for this project is located at the following folder:  
 (/Users/alexdiaz/Library/Application Support/Corona Simulator/WidgetDemo-E572DCC64EED14454989F54E89BA81C0)  
WARNING: Simulator does not support camera, photo lib or saved photos album.  
 Instead, you should create a JPEG image file and choose it in the open file dialog.  
you entered: 21  
WARNING: Simulator does not support camera, photo lib or saved photos album.  
 Instead, you should create a JPEG image file and choose it in the open file dialog.  
2011-12-14 11:46:44.411 Corona Simulator[10579:2403] glCheckFramebufferStatus error at end unbindRenderFBO  
W  

[import]uid: 95689 topic_id: 19141 reply_id: 73807[/import]

Help Peach;

I now have an error that I can’t seem to resolve. Please take a look at the following code and the error associated with it:

 local function sessionComplete ( event )  
  
 local img = event.target  
  
 end --sessionComplete  
--  
 local function newphoto ( event )  
 clearGroup( editGroup )   
 -- choose photo library for picture  
 media.show( media.SavedPhotosAlbum, sessionComplete )  
  
  
 -- create scrollView widget  
 scrollBox = widget.newScrollView{  
 -- top = display.statusBarHeight + titleBar.height,  
 width = 320,  
 height = 366,  
 maskFile = "assets/wallpaper.png"  
 }  
  
 -- insert widget into editGroup  
 editGroup:insert( scrollBox.view )  
 -- Create thumbnail  
 local thumbnail = display.newGroup()  
 thumbnail:insert( img ) -- getting error here  
 img:scale( 0.5, 0.5 )  
   
 local r = 5  
 local border = display.newRoundedRect( 0, 0, img.contentWidth + 2\*r, img.contentHeight + 2\*r, r )  
 border:setFillColor( 0,255,255,200 )  
 thumbnail:insert( 1, border, true )  
 thumbnail:translate( 0.5\*display.contentWidth, 0.5\*display.contentHeight )   
  
 end -- newphoto  

This is the error:

WARNING: Simulator does not support camera, photo lib or saved photos album.  
 Instead, you should create a JPEG image file and choose it in the open file dialog.  
Runtime error  
 /Applications/Xela Development/edit\_info.lua:219: ERROR: table expected. If this is a function call, you might have used '.' instead of ':'  
stack traceback:  
 [C]: ?  
 [C]: in function 'insert'  
 /Applications/Xela Development/edit\_info.lua:219: in function 'onPress'  
 ?: in function 'onSelection'  
 ?: in function <?:1349>  
 ?: in function <?:215>  
  

[import]uid: 95689 topic_id: 19141 reply_id: 74407[/import]

Hey Diaza,

I just spotted this thread; can you upload a copy of your project somewhere and provide a link please? (I can try run it that way and hopefully assist better.)

Peach :slight_smile: [import]uid: 52491 topic_id: 19141 reply_id: 74500[/import]

Hi Peach

I uploaded the file to GitHub but I have not learned how to use it yet, so I just created a Gist with a readme and the main.lua file. Here is the url: https://gist.github.com/1494183 or this one:
git clone git://gist.github.com/1494183.git gist-1494183

Hope you can help

Thanks [import]uid: 95689 topic_id: 19141 reply_id: 74729[/import]

Hey again,

I’ve had a little look, I’m not totally up to date on some of this stuff however I think the way to go would be removing the thumbnail and putting this in;

[lua]local function pic_photo ( event )

local img = event.target
img.width = img.width / 2
img.height = img.height /2
img.x = 160
img.y = 240

local baseDir = system.DocumentsDirectory
display.save( img, “photo.jpg”, baseDir )

end – pic_photo end[/lua]

That would show the image loaded only once - and it seems setting it to isVisible = false wont throw an error either so you can hide it on undesirable pages.

See how that goes :slight_smile:

Peach [import]uid: 52491 topic_id: 19141 reply_id: 74830[/import]

Peach

I tried it and it does work, no errors. I don’t even need to save it so I deleted:

local baseDir = system.DocumentsDirectory  
 display.save( img, "photo.jpg", baseDir )  

But I still cannot delete the image with this code:

local list, scrollBox, backButton, doneButton, pickerButton, picker,img  
  
-- private functions  
local function clearGroup( g )  
 -- remove all widgets (they must be removed manually)  
 if list then list:removeSelf(); list = nil; end  
 if scrollBox then scrollBox:removeSelf(); scrollBox = nil; end  
 if backButton then backButton:removeSelf(); backButton = nil; end  
 if doneButton then doneButton:removeSelf(); doneButon = nil; end  
 if pickerButton then pickerButton:removeSelf(); pickerButton = nil; end  
 if picker then picker:removeSelf(); picker = nil; end  
 if img then img.isVisible = false ; end  
  
 -- clear the contents of a group, but don't delete the group  
 for i=g.numChildren,1,-1 do  
 display.remove( g[i] )  
 end  
end  

which gets called on each tab bar button pressed. Any ideas?

Thanks [import]uid: 95689 topic_id: 19141 reply_id: 74849[/import]

It may be worth posting about the in the UI forum as I’m afraid my experience with this stuff is still a bit limited.

Peach :slight_smile: [import]uid: 52491 topic_id: 19141 reply_id: 74870[/import]

Are you inserting the displayed pictures into your main display group ? [import]uid: 84637 topic_id: 19141 reply_id: 74904[/import]

Danny

That’s what it was. I inserted it in the main display group and now it does go away on pressing other tab bars.

Thanks a bunch, you guys are great !! (and that means you too Peach) [import]uid: 95689 topic_id: 19141 reply_id: 74927[/import]

Danny/Peach

One more thing, I get the following error when I try to pick different photos:

2011-12-20 11:28:18.431 Corona Simulator[12153:2403] glCheckFramebufferStatus error at end unbindRenderFBO

Is there a limit to the size of the picture that Corona will read in? Its works great with images around 230kb but I get this error with images around 1M.

Thanks [import]uid: 95689 topic_id: 19141 reply_id: 74943[/import]