Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Creating Facebook app for Android - quesiton
Started by WarrenW Oct 31 2012 10:18 AM

- - - - -
72 replies to this topic
[TOPIC CONTROLS]
Page 2 of 3 1 2 3
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#26

WarrenW

[GLOBAL: userInfoPane.html]
WarrenW
  • Contributor

  • 830 posts
  • Corona SDK

Just curious why would you want to save the image displayed on your phone rather than the entire image captured by the camera? Are you still able to save the entire image or just the part that is shown on the phone?
uid: 184193 topic_id: 32551 reply_id: 130052


[TOPIC: post.html]
#27

WarrenW

[GLOBAL: userInfoPane.html]
WarrenW
  • Contributor

  • 830 posts
  • Corona SDK

So if I do the following with the media.show it will save the image to the filename specified?

media.show( media.Camera, onComplete,{ baseDir=system.ResourceDirectory, filename="picture1.jpg", type="image" } )

Thanks!
uid: 184193 topic_id: 32551 reply_id: 130061


[TOPIC: post.html]
#28

WarrenW

[GLOBAL: userInfoPane.html]
WarrenW
  • Contributor

  • 830 posts
  • Corona SDK

Here is what I did and it took the picture from the camera but returned back to the main screen to tap to launch the camera. It did not show the Facebook login part. Why?

-----------------------------------------------------------------------------------------
--
-- main.lua
--
-----------------------------------------------------------------------------------------

-- Your code here

local facebook = require "facebook"
 
local appId = "12434435235325432543254"
 

local bkgd = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
bkgd:setFillColor( 128, 0, 0 )

local text = display.newText( "Tap anywhere to launch Camera", 0, 0, nil, 16 )
text:setTextColor( 255, 255, 255 )
text.x = 0.5 * display.contentWidth
text.y = 0.5 * display.contentHeight
local onComplete = function(event)
   local photo = event.target
   photo.isVisible = false
   facebook.login( appId, fbListener, { "publish_stream" } )
end
 
local function fbListener( event )
    if event.isError then
        native.showAlert( "ERROR", event.response, { "OK" } )
    else
        if event.type == "session" and event.phase == "login" then
            -- login was a success; call function
            onLoginSuccess()
       
        elseif event.type == "request" then
            -- this block is executed upon successful facebook.request() call
 
            native.showAlert( "Success", "The photo has been uploaded.", { "OK" } )
        end
    end
end
 
local function onLoginSuccess()
    -- Upload 'iheartcorona.jpg' to current user's account
    local attachment = {
        message = "Just a description of the photo.",
        source = { baseDir=system.ResourceDirectory, filename="picture1.jpg", type="image" }
    }
   
    facebook.request( "me/photos", "POST", attachment )
end

local listener = function( event )
	if media.hasSource( media.Camera ) then
		media.show( media.Camera, onComplete,{ baseDir=system.ResourceDirectory, filename="picture1.jpg", type="image" } )
	else
		native.showAlert("Corona", "Camera not found.")
	end
	return true
end

bkgd:addEventListener( "tap", listener )
uid: 184193 topic_id: 32551 reply_id: 130062


[TOPIC: post.html]
#29

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Contributor

  • 751 posts
  • Corona SDK

@Joshua,
I took a snapshot with display.save and emailed it to myself and the image is showing the same issue of being VERY distorted... I have a Galaxy SIII but I do have it rooted and running cynogenmod, so I wonder if that could have anything to do with it? For now I will try and have a friend test this as well.
uid: 19620 topic_id: 32551 reply_id: 130102


[TOPIC: post.html]
#30

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Contributor

  • 751 posts
  • Corona SDK

@joshua,
just tested it on a stock unrooted phone and am seeing the same problem, I can send you images of what it looks like if it would be helpful...

Also display.captureScreen seems to work fine except that using that API call only allows you to save the screen capture to the users photo album right? No way to just email it or paste it to facebook from the corona apps temp/documents?
uid: 19620 topic_id: 32551 reply_id: 130103


[TOPIC: post.html]
#31

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

rxmarccall,

Sounds like you've found a bug with display.save(). It may be device specific or its the pixel size of the image that you are capturing (ie: a stride issue), because this issue does not happen on my Galaxy Nexus. Probably some edge case that we didn't think of.

Would you mind sending us a small sample project that reproduces this display.save() issue please? You can do so by clicking the "Report a Bug" link at the top of this web page.
uid: 32256 topic_id: 32551 reply_id: 130108


[TOPIC: post.html]
#32

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Contributor

  • 751 posts
  • Corona SDK

@Joshua,
I submitted a bug report as requested. As I built a demo to show the issue I found what seems to be causing the issue. When my project had no "config" file, there was no issue. Once I put in my projects "config" file that set the applications content width and height, then the crazy warping on the saved image is happening. Hope this one can get resolved somewhat quick so I can get my app out!

Thanks
uid: 19620 topic_id: 32551 reply_id: 130236


[TOPIC: post.html]
#33

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

I'm thinking that this must be a "stride" issue. That is, the image comes out skewed because the number of pixels along the horizontal axis is not a multiple of 4. I also suspect that this only happens on particular Android devices. I say this because I remember something similar happening to one other person, but I wasn't able to reproduce it with his project on my Android devices.

So, can you tell me the make and model of the Android device that you are using please?
uid: 32256 topic_id: 32551 reply_id: 130255


[TOPIC: post.html]
#34

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Contributor

  • 751 posts
  • Corona SDK

@Joshua,
Sure, my phone is the "Samsung Galaxy SIII". My brother also had the same issue and he has the "HTC One S"
uid: 19620 topic_id: 32551 reply_id: 130324


[TOPIC: post.html]
#35

WarrenW

[GLOBAL: userInfoPane.html]
WarrenW
  • Contributor

  • 830 posts
  • Corona SDK

Hi,

I added code to login to Facebook with only using the app id and did not do anything else on the app page in the developers page. I didn't enter a class name or hash and when i try to login it lets me. But when i try to upload a photo it says it was a success but it's not on my Facebook page. Is this still because I do not have anything else configured on the Facebook developers page? If so, why did it say I am logged in and the photo uploaded? This is for Android and below is my code. The app id is removed on this page.

UPDATE: Since I posted this I did the following. I commented out the line to upload the photo and instead had it just post a message. This works! The message appeared on my Facebook page. I then noticed I was calling the picture from the wrong directory and fixed it and tried again. It seemed longer before it said the image was uploaded but nothing appears on my page with the POST. Any suggestions why it works with the message but not with the attachment and the picture? Thanks!!

	--facebook.request( "me/feed", "POST", attachment )
	facebook.request( "me/feed", "POST", {message = "Hello Facebook"} )

Thanks

-----------------------------------------------------------------------------------------

--

-- main.lua

--

-----------------------------------------------------------------------------------------
local facebook = require "facebook"
local appId = "removed"
local widget = require "widget"

local onComplete = function(event)
   local photo = event.target
   photo.isVisible = false
   facebook.login( "removed", fbListener, { "publish_stream" } )
end

 local function fbListener( event )
    if event.isError then
        native.showAlert( "ERROR", event.response, { "OK" } )
    else
        if event.type == "session" and event.phase == "login" then
            -- login was a success; call function
                native.showAlert( "Success", "You are logged into Facebook!.", { "OK" } )           
                --onLoginSuccess()
      

        elseif event.type == "request" then
           -- this block is executed upon successful facebook.request() call
 

            native.showAlert( "Success", "The photo has been uploaded.", { "OK" } )
        end
    end
end

local function onLoginSuccess()
    -- Upload 'iheartcorona.jpg' to current user's account
    local attachment = {
        message = "Just a description of the photo.",
        source = { baseDir=system.TemporaryDirectory, filename="CameraShot.jpg", type="image" }
    }
    facebook.request( "me/photos", "POST", attachment )
end

local onComplete = function(event)
   if event.completed then

      -- Camera shot was successfully taken.

      -- Display at full resolution by passing in true.

      -- display.newImage("CameraShot.jpg", system.TemporaryDirectory, true)
                local attachment = {
                message = "Just a description of the photo.",
	        source = { baseDir=system.TemporaryDirectory, filename="CameraShot.jpg", type="image" }
	        }

  
    facebook.request( "me/photos", "POST", attachment )

   else

      -- User canceled out.

   end
end

local listener = function( event )
                if media.hasSource( media.Camera ) then
                                local filePath = { baseDir = system.TemporaryDirectory, filename = "CameraShot.jpg" }
                                media.show( media.Camera, onComplete, filePath )
                else
                                native.showAlert("Corona", "Camera not found.")
                end
                return true
end

local onbtnLoginEvent = function (event )
    if event.phase == "release" then
                print( "You pressed and released a button!" )
                --native.showAlert( "Success", "The button was pressed!.", { "OK" } )
                facebook.login( appId, fbListener, { "publish_stream" } )
    end
end

local onbtnCameraEvent = function (event )
    if event.phase == "release" then
            local filePath = { baseDir = system.TemporaryDirectory, filename = "CameraShot.jpg" }
            media.show( media.Camera, onComplete, filePath )
    end
end

local btnLogin = widget.newButton{
    id = "btn001",
    left = 100,
    top = 200,
    label = "Facebook Login",
    width = 170, height = 28,
    cornerRadius = 8,
    onEvent = onbtnLoginEvent
}

btnLogin.x = 100
btnLogin.y = 200

local btnCamera = widget.newButton{
    id = "btn002",
    left = 100,
    top = 400,
    label = "Take Picture",
    width = 170, height = 28,
    cornerRadius = 8,
    onEvent = onbtnCameraEvent
} 

btnCamera.x = 100
btnCamera.y = 400
uid: 184193 topic_id: 32551 reply_id: 130452


[TOPIC: post.html]
#36

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

warrenwsav,

I remember facebook limiting the number of posts that I can do to someone's page within an hour. I've seen this during testing. I'm not sure if facebook is supposed to do that (I haven't found documentation about it) or if they were just filtering them out because the my posts were all the same. Or worse, flagging them as spam. In any case, I hope you don't get bit by that too during testing.
uid: 32256 topic_id: 32551 reply_id: 130477


[TOPIC: post.html]
#37

WarrenW

[GLOBAL: userInfoPane.html]
WarrenW
  • Contributor

  • 830 posts
  • Corona SDK

Thanks for the suggestion but that's not it. I can run my app right now and it will post a text message. But when I try to send a picture it takes forever and says it was successfully uploaded but it's not on my Facebook page. I have changed the filename, etc. I know the picture exists on the phone because I added code to show it right before the upload and it is there.

Anyone have any idea?

Thanks,

Warren
uid: 184193 topic_id: 32551 reply_id: 130564


[TOPIC: post.html]
#38

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

I recommend that you add some
print()
statements to your code and make sure that you are actually making it to your
facebook.request()
function call. You can view your print statements in the Android log via the Android SDK tools "adb logcat" or "ddms". Also keep on the look out for any errors printed by facebook about your photo not getting uploaded. That's as much as I can suggest at the moment.
uid: 32256 topic_id: 32551 reply_id: 130723


[TOPIC: post.html]
#39

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Contributor

  • 751 posts
  • Corona SDK

@Joshua,
Any chance the bug that I submitted a while back is going to get resolved anytime soon? Pretty much just waiting on that to release my app.
uid: 19620 topic_id: 32551 reply_id: 131639


[TOPIC: post.html]
#40

mpappas

[GLOBAL: userInfoPane.html]
mpappas
  • Contributor

  • 527 posts
  • Enterprise

@rxm - We're taking photos, using display.save, emailing them, posting them to facebook, showing them onscreen, etc... on a galaxy s3 (4.0.1 I believe). We're also passing the same images to a nexus 7, ipad, iphones, etc, and they look fantastic across all platforms. (wasn't easy though)

Our content width and height is 640x960, and the app had squishing/distortion effects early on...

Images taken on some devices seemed stretched vertically, other stretched horizontally...

It turned out that there were some issues based on the apps content width/height related to the devices native resolution.

If you read the display.capture stuff carefully (the really really fine print), it says the capture stuff happens *in device pixels*... which you can compensate for easy enough (as long as you know of it).

Capturing at device pixel resolution made for some really really huge image grabbing on an ipad3, I tell ya -- that had to be fixed too...

But then it got harder. When I took pictures on devices with native resolution that wasn't as wide (or tall) as my content width/height, the display capture would just grab what it could.

But this left my image at an aspect ratio that was different than my intention (so a 640x960 intended capture, would be returned as a 540x960 capture -- the best it could do on the device). Later, when the picture is displayed, my code would expand it to 640x960 and voila... It's stretched...

It took a while (including dealing with landscape photos, etc) to get it all nice and perty, and our solutions are specific to what we're doing, but some of this might be related (I relate all this because our images looked funky early on).
uid: 79933 topic_id: 32551 reply_id: 131645


[TOPIC: post.html]
#41

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Contributor

  • 751 posts
  • Corona SDK

@mpappas,
Thanks for sharing your experience with this. I set my own content width and height as well at the start of the project so that our app content would display well on any device possible. Its working great, but I just don't see it as a solution to mess with our apps content area size at this point because we would have to redo almost everything in the app. our content size is a width of 320 by a height of 480. I thought that this would be a frequently used content size? isn't that the size of the original iphone resolution?
uid: 19620 topic_id: 32551 reply_id: 131646


[TOPIC: post.html]
#42

lano78

[GLOBAL: userInfoPane.html]
lano78
  • Contributor

  • 370 posts
  • Corona SDK

Didn't read the entire thread but regarding Facebook, you should sandbox your app in the app settings page on Facebook. I learned that when I was playing around with facebook checkins.
uid: 13560 topic_id: 32551 reply_id: 131651


[TOPIC: post.html]
#43

mpappas

[GLOBAL: userInfoPane.html]
mpappas
  • Contributor

  • 527 posts
  • Enterprise

@rxm - there's a lot of sizes these days, but a couple questions...

What size are the saved images? For things to not look squished/stretched, they need to be captured at the same ratio as your content dimensions, eg; 2:3 (320:480)

But come to think of it, one thing I didn't consider is a content mode of zoom stretch (or any other mode that would stretch things one way or another).

If you're doing a content stretch, then your likely to have a rough time getting your captured images to look nice on various devices... (I would steer away from that...)

Either way, you should check your saved image sizes on various devices, and consider the impact of displaying then on at your content resolution (and then, on top of that, factor in zoom stretching or any other mode like that you might be using).
uid: 79933 topic_id: 32551 reply_id: 131656


[TOPIC: post.html]
#44

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Contributor

  • 751 posts
  • Corona SDK

I am using letterbox so none of that should be an issue. Bottom line is that we shouldn't need to screw around and find loop holes and have to alter the integrity of our apps to get this working, for that reason I hope Ansca can fix this bug. Otherwise developers will look else where for their dev tools, just sucks when features don't work.
uid: 19620 topic_id: 32551 reply_id: 131667


[TOPIC: post.html]
#45

mpappas

[GLOBAL: userInfoPane.html]
mpappas
  • Contributor

  • 527 posts
  • Enterprise

@rxm, display.save works in device pixels -- Letterbox mode has most (if not all) of the issues I outlined above, and depending on the devices the images were saved from, and later displayed on (both being the same letterbox app), you can get stretched/squashed images. (our config.lua settings are similar).

    content =
    {
            width = 640,
            height = 960,
            scale = "letterbox"
    },

Again, there's not enough info to tell if this is what is causing your distortions, but my image processing code takes images from iphones, s3's, nexus 7's, motorolas, iPads etc, accounts for those factors, and the final images are distortion free (across all devices).

Also, You never answered about the pixel sizes of your images when saved from various devices. If they are all a perfect 320x480 when saved from very different devices, then you must have accounted for the issue. If they aren't all the same sizes (320x480), you might want to reread my prior posts.

Best of luck.
uid: 79933 topic_id: 32551 reply_id: 131673


[TOPIC: post.html]
#46

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Contributor

  • 751 posts
  • Corona SDK

@mpappas,
I guess thats what I don't understand is exactly how to resolve my issue. Can you change what resolution the screen is captured at? My phone is the galaxy SIII, so my captured image size is 1280x720. What other info do you need?
uid: 19620 topic_id: 32551 reply_id: 131675


[TOPIC: post.html]
#47

mpappas

[GLOBAL: userInfoPane.html]
mpappas
  • Contributor

  • 527 posts
  • Enterprise

The capture image size tells me you have a scaling problem. You are displaying images at your content size of 320x480 --- a 2:3 pixel ratio, width to height.

However, you are capturing images from this particular device at 720x1280 --- closer to a 1:2 pixel ratio.

When you call display capture with a size of 320x480, it captures IN DEVICE PIXELS... And the s3 screen is not a 2:3 aspect ratio. At this point we come up against how corona is mapping your 320x480 space onto the s3... Which will determine how many pixels you get back from the capture call... Back to that in a minute...

So --- If you display a captured/saved 720x1280 image in your content space (320x480), i believe it would be squished, as the SDK crunches approx 200 pixels off the 1280 dimension when it tries to display it (as 320x480). A few taps on a calculator, and you can see the math issue...

Hopefully that part makes sense... Why does corona do it this way you might ask? The SDK allows you to capture from the display in however many pixels are possible on the device. That way, if you are using a lower content resolution, you can still opt to capture high res images (up to the displays true resolution).

Two variables that are useful in understanding how to adjust the height and width of your display.capture() height/width are:

display.contentScaleX
display.contentScaleY

You should print those out (either onscreen, or in the console) and consider multiplying your display capture width/height by them / and or other transformations to your captured photo based on, well, a variety of factors...

I believe once you multiply by those (your capture height/width), your saved images will become 320x480... From there, you've got more work to do, but you might gain some insight as to whats going on under the hood on various devices...
uid: 79933 topic_id: 32551 reply_id: 131678


[TOPIC: post.html]
#48

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Contributor

  • 751 posts
  • Corona SDK

Thanks for your help first of all.
So I now understand the issue, thanks for explaining it so fully. So my question now is.... are you able to use parameters with the display.capture API in regards to telling it was aspect ratio to save the image at? Or in the end do I have to still fix this by changing up my app's config settings width and height?

for example can you do something like display.capture( 480, 320 )....?
uid: 19620 topic_id: 32551 reply_id: 131686


[TOPIC: post.html]
#49

mpappas

[GLOBAL: userInfoPane.html]
mpappas
  • Contributor

  • 527 posts
  • Enterprise

Not exactly, but changing the size of the object (the first parameter argument to display.save) effectively does the same thing, eg;If you change the image width and height you are passing, it does the same thing.

From the display.save doc page:

NOTE: When dynamic content scaling is enabled, display.save() saves the image in the device's native resolution. For instance, if this method is used to save a 100 x 200 pixel display object, it will be saved as a 100 x 200 image on iPhone3 but it will be a 200 x 400 image on an iPhone4 (which would have the same content dimensions but more actual pixels). This is assuming that the config.lua file specifies the content width/height as 320x480 respectively.

So if you change the height and width of the image to take this into account before calling display.save, that will achieve the effect.
uid: 79933 topic_id: 32551 reply_id: 131687


[TOPIC: post.html]
#50

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Contributor

  • 751 posts
  • Corona SDK

Ahhh ok I finally get it. Only issue is that I have LOTS of display objects that get captured, is it possible to change the width and height of a display group? Or would I need to change each display object individually you think?
uid: 19620 topic_id: 32551 reply_id: 131688



[topic_controls]
Page 2 of 3 1 2 3
 
[/topic_controls]