Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

[FIXED] display.captureBounds bug?
Started by Develephant Oct 13 2013 03:45 AM

11 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Develephant

[GLOBAL: userInfoPane.html]
Develephant
  • Corona Geek

  • 1,457 posts
  • Corona SDK

I was pulling my hair out trying to figure out a capture issue when it occurred to me to check it in the daily.  Sure enough it works fine in the daily, but not Graphics 2.0 beta.

 

Code:

 

local d = display.newImage( "gfx/photo.jpg" )
 
local xScale = display.contentWidth / d.contentWidth
local yScale = display.contentHeight / d.contentHeight
 
local scale = math.max( xScale, yScale )
 
d:scale( scale, scale )
d.x = display.contentCenterX
d.y = display.contentCenterY
 
local _c = display.captureBounds( d.contentBounds, true )

 

zoomEven : Graphics 2.0

 

Result:

Attached File  Picture 1.png   603.44KB   83 downloads

 
 

zoomEven : Build 2013.1233

 
Result:
Attached File  Picture 2.png   625.38KB   81 downloads

 

 

Now, interestingly enough, the file that saves from the G2.0 version is a much nicer resolution ( I scaled the attached image 50% so I could upload it to the forum ) but it is being visually "cropped" as shown.

 

The other image from the daily build comes out at a much lower resolution, but outputs correctly.

 

What would be great is that nice high res from the G2 version, but fitting correctly.

 

Any suggestions?  Or is this something that needs to be addressed?

 

Thanks in advance. 



[TOPIC: post.html]
#2

RedBeach

[GLOBAL: userInfoPane.html]
RedBeach
  • Corona Geek

  • 1,132 posts
  • Corona SDK

Hi develephant.


Thanks for posting that info. Have you already submitted that bug for Corona?



[TOPIC: post.html]
#3

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,534 posts
  • Enterprise

Please submit a bug report.  Use the "Report a bug" feature at the top right of the page.  



[TOPIC: post.html]
#4

Fat Red Couch

[GLOBAL: userInfoPane.html]
Fat Red Couch
  • Enthusiast

  • 34 posts
  • Corona SDK

Also, I don't believe display.captureBounds() works on device at the moment (display.capture is listed as a "known issue" on device for gfx 2.0).

 

Any estimate as to when the display.captureBounds() API will work on device for gfx 2.0 builds?



[TOPIC: post.html]
#5

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,534 posts
  • Enterprise

Some of this is still a work in progress.  Engineering needs to know about these which is why we ask for the bug reports.

 

Thanks

Rob



[TOPIC: post.html]
#6

Develephant

[GLOBAL: userInfoPane.html]
Develephant
  • Corona Geek

  • 1,457 posts
  • Corona SDK

I have submitted the bug a couple of days ago, fyi.



[TOPIC: post.html]
#7

jen.looper

[GLOBAL: userInfoPane.html]
jen.looper
  • Contributor

  • 164 posts
  • Corona SDK

I'm trying to figure out display.captureScreen(). For some reason this code snippet:

 

local screenCap = display.captureScreen()
            
           local baseDir = system.TemporaryDirectory
           display.save( screenCap, "photo.jpg", baseDir )
           screenCap:removeSelf()
           screenCap = nil
 
just saves about 1/4 of the screen to my tempDir. Help? Using graphics 2.0 Build: 2013.2035


[TOPIC: post.html]
#8

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

I see one problem with your code.  It is capturing the screen twice.  The display.save() function that you're calling is effectively capturing the "screen capture".  This is a performance issue and will take twice as much memory... which would be very noticeable on an iPad retina.  A better solution would be the following, which should also work-around the bug that you've found...
 

local baseDir = system.TemporaryDirectory
display.save( display.currentStage, "photo.jpg", baseDir )

 
Have a look at sample project "Storage/ScreenCaptureToFile" that is included with the Corona Simulator for an example of this.  It captures the screen as shown above and then displays it on screen.

 

That said, you've probably found a legitimate bug.  I haven't tried it for myself yet, but I'm guessing that when you do the display.captureScreen() call, the capture image that is shown on screen is bigger than the content that was actually captured.  Right?  You can prove this by commenting out the removeSelf() part in your code.



[TOPIC: post.html]
#9

jen.looper

[GLOBAL: userInfoPane.html]
jen.looper
  • Contributor

  • 164 posts
  • Corona SDK

Yes! That did create a nice workaround, one step closer to my contest submission, mua ha ha ....

 

With regards to the other issue, yes, you're right, with just a display.captureScreen() call, only the bottom 1/4th of the screen is saved. I was also throwing some strange errors when experimenting with captureBounds:

 

Corona Simulator(47094,0x7fff7761c310) malloc: *** mach_vm_map(size=18446737476639784960) failed (error code=3)

 

*** error: can't allocate region

 

*** set a breakpoint in malloc_error_break to debug

 

capture bounds in content units: x: -2147483648 y: -384 w: -2147483648 h: 360

 

capture bounds in pixels: x: 0 y: 0 w: -2147483648 h: 768

 

Nov  4 21:08:20 Administrators-MacBook-Pro-2.local Corona Simulator[47094] <Error>: CGImageCreate: unsupported image width: 2147483648.

 

Nov  4 21:08:20 Administrators-MacBook-Pro-2.local Corona Simulator[47094] <Error>: Unsupported dimensions - 0 x, 0 y, 2147483648 width, 768 height, 8589934592 bytes-per-row

 

Nov  4 21:08:20 Administrators-MacBook-Pro-2.local Corona Simulator[47094] <Error>: CGBitmapContextCreateWithData: failed to create delegate.

 

Nov  4 21:08:20 Administrators-MacBook-Pro-2.local Corona Simulator[47094] <Error>: CGContextDrawImage: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

 

Nov  4 21:08:20 Administrators-MacBook-Pro-2.local Corona Simulator[47094] <Error>: CGBitmapContextCreateImage: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

 

Nov  4 21:08:20 Administrators-MacBook-Pro-2.local Corona Simulator[47094] <Error>: ImageIO: CGImageDestinationAddImage image parameter is nil

 

Nov  4 21:08:20 Administrators-MacBook-Pro-2.local Corona Simulator[47094] <Error>: ImageIO: CGImageDestinationFinalize image destination must have at least one image



[TOPIC: post.html]
#10

albert90

[GLOBAL: userInfoPane.html]
albert90
  • Enthusiast

  • 82 posts
  • Corona Staff

The behavior of display.captureBounds() should be correct in the next Graphics 2.0 daily build. Please let us know if you have any further problems. Thanks!



[TOPIC: post.html]
#11

RedBeach

[GLOBAL: userInfoPane.html]
RedBeach
  • Corona Geek

  • 1,132 posts
  • Corona SDK

Nice. Thanks Albert



[TOPIC: post.html]
#12

jen.looper

[GLOBAL: userInfoPane.html]
jen.looper
  • Contributor

  • 164 posts
  • Corona SDK

awesome, thanks! :)




[topic_controls]
[/topic_controls]