And what would be the path to use for the photo library? [import]uid: 17969 topic_id: 15661 reply_id: 115438[/import]
I think you don’t need to know the path to photo library. Corona will save it for you.
media.save( “MyPhoto.jpg”, systemDocumentsDirectory ) [import]uid: 138389 topic_id: 15661 reply_id: 115442[/import]
You cannot set the destination path. That is out of your control. This is because the photo gallery on iOS is sandboxed, so this is out of our control too. You can only provide the source path of the image file that you want to add to the photo gallery. [import]uid: 32256 topic_id: 15661 reply_id: 115445[/import]
Ah, I misread it, the basedir is of curse where the file is, not where its oing. Aweome, got pretty much all I need for now then fo my photo app
[import]uid: 17969 topic_id: 15661 reply_id: 115452[/import]
Joshua Quick, can you help me?
I’m trying to savethe full-resolution of an image from PhotoLibrary to system.DocumentsDirectory with
[lua]media.show( mediaSource, listener [, file] )[/lua]
I added the “android.permission.CAMERA” and android.permission.WRITE_EXTERNAL_STORAGE" permissions
My version of this is:
[lua]local onComplete = function(event)
– do nothing
end
file =
{
baseDir = system.DocumentsDirectory,
filename = “imageName.jpg”,
type = “image”
}
media.show( media.PhotoLibrary, onComplete, file )[/lua]
The image is saved but when I open it with default phone image viewer there is just black color. [import]uid: 138389 topic_id: 15661 reply_id: 115816[/import]
vovasoft,
I’m not sure what you mean by “default phone image viewer”. Do you mean Android’s standard “Gallery” app? If it is displaying a black image, well then that is a bug on Google’s end, not ours. The photo that you are saving to your Documents directory is just a “file copy” of the image file in the Gallery app.
Now, if the image that is in your Documents directory is solid black, then that’s a different story. If that is the issue, then what happens if you display that image via [lua]display.newImageRect()[/lua] within Corona? Does it display correctly? It has for all of my tests. I’ve also successfully e-mail that saved photos via our [lua]native.showPopup()[/lua] API as well. [import]uid: 32256 topic_id: 15661 reply_id: 115825[/import]
Joshua Quick,
- Yes I mean Android standard “Gallery” app. I tried other 4 different image viewer but all said operation failed and my file browser shows me “operation failed” in MD5 description of image but the file size is the same of the photo from Gallery…
- It’s ok when I open the image via display.newImageRect() within Corona but how to get width and height of images ? I cannot create an image without width and height.
- Then I e-mail that saved photo via native.showPopup()
[lua]local options =
{
to = “user@name.com”,
subject = “Image”,
body = “some text”,
attachment = { baseDir=system.DocumentsDirectory,
filename=“imageName.jpg”, type=“image” },
}
native.showPopup(“mail”, options)[/lua]
I receive an error “cannot attach the file” with android default e-mail client.
But it works ok with gmail e-mail app from appstore but the default browser is more important
My android version is: 2.3.6
What do you think ? [import]uid: 138389 topic_id: 15661 reply_id: 115847[/import]
So, I assume you are trying to do use the [lua]media.save()[/lua] function, correct? Is that what is failing on you? Because your sample code up above is using [lua]media.show()[/lua]. That’s why I’m a bit confused here. [import]uid: 32256 topic_id: 15661 reply_id: 115849[/import]
No. I’m trying to copy a photo from Photo Gallery using [lua]media.show()[/lua].
[lua]local onComplete = function(event)
– do nothing
end
file =
{
baseDir = system.DocumentsDirectory,
filename = “imageName.jpg”,
type = “image”
}
media.show( media.PhotoLibrary, onComplete, file )[/lua]
I don’t want to display it, just to save the chosen image to a file.and store the filename in json file, I will use the image in the future.
It works ok but
When I load the saved image using
[lua]display.newImageRect( [parentGroup,] filename [, baseDirectory] width, height ) [/lua]
I don’t know the original width and height of that photo. What can I do ? [import]uid: 138389 topic_id: 15661 reply_id: 115860[/import]
Oh, yeah, Corona does not provide an API for fetch width/height from an image file. You have to use [lua]display.newImage()[/lua] in this case since you do not know the width and height of the image. That function will automatically downscale the image “proportionally” to fit within OpenGL’s constraints.
You can scale it lower from there to fit within the screen’s bounds if needed. You should use the display object’s [lua]scale()[/lua] function to downscale. Never adjust an image object’s width and height. Those 2 properties indicate the image’s width and height in pixels and they do NOT change when scaling the object. The [lua]contentWidth[/lua] and [lua]contentHeight[/lua] properties are the width and height of the object onscreen and these do change when scaling the object.
Now, if the image fails to load, then it sounds like the save-to-file operation failed. Perhaps because you are out of storage space. Have a look at your Android’s log output for clues, which you can view via “adb logcat” or “DDMS”. [import]uid: 32256 topic_id: 15661 reply_id: 115864[/import]
Joshua Quick , You helped me a lot. Thank you.
That function will automatically downscale the image “proportionally” to fit within OpenGL’s constraints.
What are this OpenGL’s constraints ? [import]uid: 138389 topic_id: 15661 reply_id: 115920[/import]
We use OpenGL (Open Graphics Library) to render content with hardware acceleration. The graphics hardware has a limit to how large an image/texture it can hold in memory. This is referred to as the “max texture size” (aka: GL_MAX_TEXTURE_SIZE), which is the maximum width/height of a texture it can hold in pixels. The maximum varies between different graphics hardware, but on average, I find most mobile devices support up to 2048 pixels.
On the old Droid, the max is 1024 pixels. (Pathetically small.)
I find most Android devices support a max texture size of 2048 pixels.
This max texture size usually comes into play with photos because they are usually larger than what OpenGL can display. In order to display a large photo selected from the gallery, Corona has no choice but to downscale the image in memory before feeding it to OpenGL in order to render it. This is really done via downsampling, which means we skip every other pixel in the image file when loading it into memory. There is really no other way to do it. But that said, the image will still be displayed within your app and it will still appear super huge. So, likely you will never notice this is happening unless you look at your Android device’s log output which will indicate when downsampling has occurred. If your device does not have enough memory to load the image, then the log output will indicate this as well. That’s more likely to happen on older device with low RAM and if that case occurs, Corona will attempt to load the image one more time by downsampling it further, but if that final attempt fails, then we have no choice but to give up. [import]uid: 32256 topic_id: 15661 reply_id: 115926[/import]
-
Corona will attempt to load the image one more time by downsampling it further, but if that final attempt fails, then we have no choice but to give up.
The code will stop running or it will continue to run the code ? -
What about the error I mentioned above ?
I receive an error “cannot attach the file” with android default e-mail client.
But it works ok with gmail e-mail app from appstore but the default browser is more important
My android version is: 2.3.6
What do you think ? [import]uid: 138389 topic_id: 15661 reply_id: 115928[/import]
vovasoft,
If Corona fails to load the image, then its associated function such as [lua]display.newImage()[/lua] is “supposed” to return nil. Either that or a blank polygon. Unfortunately, I personally don’t remember which it does… but it definitely does not crash.
Regarding the error, I’m not sure what to think. No one else has mentioned a similar issue and we can’t reproduce it, so you’ll need to isolate it. I suggest that you look at the Android device log output via “adb logcat” or “ddms” to get more details. For example, it might be that the photo file is too large for the e-mail app to send and that’s why it’s failing… but only the log can provide that kind of detail. [import]uid: 32256 topic_id: 15661 reply_id: 115935[/import]
The only error I found with logcat is
[java][07-18 22:50:50.832 1741:0x8a1 E/UsbStorageConnector]
Error in NativeDaemonConnector
java.io.IOException: No such file or directory
at android.net.LocalSocketImpl.connectLocal(Native Method)
at android.net.LocalSocketImpl.connect(LocalSocketImpl.java:238)
at android.net.LocalSocket.connect(LocalSocket.java:98)
at com.android.server.NativeDaemonConnector.listenToSocket(NativeDaemonConnector.java:102)
at com.android.server.NativeDaemonConnector.run(NativeDaemonConnector.java:85)
at java.lang.Thread.run(Thread.java:1019)[/java]
It is fired up every 5 seconds [import]uid: 138389 topic_id: 15661 reply_id: 115945[/import]
You said it works with the “gmail e-mail app”, but not with the browser. I don’t really understand what you are doing. If you are e-mailing the file via the [lua]native.showPopup(“mail”)[/lua] and it works, then why not use that method? If you are trying to e-mail the file via a web popup then that is something we’ve never tried before and it’s up to you to figure that out. We’ve gone well out of our way on our end to make Corona support e-mail files via our [lua]native.showPopup()[/lua] function, it’s well tested, and it works… so I suggest you use it. [import]uid: 32256 topic_id: 15661 reply_id: 115947[/import]
Not browser but file browser. I said it works with the “gmail e-mail app”, but not with “default android email app” that is used by most people.
I know that [lua]native.showPopup(“mail”)[/lua] works with files, but when i try to e-mail an image that previously was saved using this code
[lua]local onComplete = function(event)
– do nothing
end
file =
{
baseDir = system.DocumentsDirectory,
filename = “imageName.jpg”,
type = “image”
}
media.show( media.PhotoLibrary, onComplete, file ) [/lua]
the image cannot be send via default android email app. [import]uid: 138389 topic_id: 15661 reply_id: 115949[/import]
Okay, we’re not getting anywhere on this forum thread. 
I know for a fact that this works, but there must be a bug in your code. Like your app is trying to e-mail the file before your onComplete() event has been triggered… thus the file doesn’t exist yet.
How about you send us a bug report with a small zipped up sample project that can reproduce this issue. You can do so by clicking the “Report A Bug” link at the top of this web page. [import]uid: 32256 topic_id: 15661 reply_id: 116093[/import]
Ok. I will send the report like you said.
One more question: Is there a way to save/backup a file to sdcard or external sdcard with LuaFileSystem ? [import]uid: 138389 topic_id: 15661 reply_id: 116296[/import]
Regarding writing to the SD card, there isn’t a reliable way to do this right now. The problem is that you don’t want to hard code the path to the SD card because there isn’t a standard path between different Android device manufacturers. The proper way to do this is to fetch the path to “external storage” from the Android OS and use that path. We would have to provide an API in Corona in order to do this. [import]uid: 32256 topic_id: 15661 reply_id: 116747[/import]