I want to take a photo and save them within a custom album on a iPad.
I tried a lot of things but ended always with wrong image orientation.
My current procedure is:
Take photo with Xamarin.Media and safe image somewhere in my app path
Create custom album if it's not existing
Load image from temporary path and save to the album
Add the image (asset) additionally to the custom album created in 2.
The workflow above is fully working except of saving the correct orientation. After loading an image with library.AssetForUrl() the containing orientation is every time up. Also after converting from asset -> CGImage -> UImage (uiImage.Orientation).
In step 3 I tried to set the orientation the the appropriate one with
var image = new UIImage(tempImage.CGImage, 1.0f, UIImageOrientation.MyOrientation)
and also with the save command
library.WriteImageToSavedPhotosAlbum(image.CGImage, myOrientation, SaveCompletionBlock)
But the orientation is still ignored. I checked this by opening the Album application as well as loading the file in my self written gallery app.
I want to avoid the use of the iOS picker to take photos. This will produce a mess of code!
Or is there any third party library which allows to take photos and store them in a custom album? Which takes care of all the metadata information? It doesn't matter if it's written in objective-c or c#. I will create bindings for it. But it's awful to work with the camera and albums in iOS.
There are tons of hand-made UIImagePickerController alternatives. Some of them:
https://github.com/w5mith/WSAssetPickerController
https://github.com/chute/photo-picker-plus-ios
https://github.com/B-Sides/ELCImagePickerController
Related
Is it possible to insert a new PHAsset to an appointed index in the camera roll?
I tried following:
let cam_req = PHAssetCollectionChangeRequest(for: camera_roll)
cam_req?.insertAssets([asset] as NSArray, at: IndexSet(integer: pos))
doesn't work.
The Camera Roll is like a stack. It's sorted by import date. There is no way to change the order or to insert a photo/video at a specific position. If you want to do that you have to create a custom user album. Custom user albums contain references to the originals in the Camera Roll and can be reordered.
http://www.tapsmart.com/tips-and-tricks/album-order-reordering-photos-album-ios-12-guide/
It’s important to note that this only works for custom photo albums you’ve created yourself – default albums like “All Photos” and “Favorites” are arranged chronologically and can’t be rearranged this way.
then it's impossible to change the order of “All Photos” and “Favorites” manually - on API level should also be limited.
I have some code that will select an image from either the user's photo library or from their camera and display it in an image view. I'm accessing the photo URL from the following line of code:
let pickedPhotoURL: URL = (info["UIImagePickerControllerImageURL"] as? URL)!
This works perfectly when accessing a photo from the user's library. However, I'll always get a nil value at this line why trying to access the photo via the camera. Anyone have any ideas / suggestions?
It's because that value isn't set for a camera. Use UIImagePickerControllerOriginalImage (or edited image if you are using that).
That key gives you a UIImage -- if you need a URL, you need to save it somewhere.
Also, don't use strings, there are keys defined for you.
In AppStore(China), an App called Tencent Mobile Manager released a series of functions related to photos, including detecting whether a photo is a screenshot taken by user, deleting photos.
I got screenshots of this app to demonstrate my question here (I added English texts myself for you since the app only shows Chinese):
This app knows what photos are screenshots and what not
When you tap Delete Button at the bottom, it shows:
Asking permission from user to delete photos
As far as I know, Photo APIs (AssetsLibrary, PHPhotoLibrary) in iOS don't give an absolute path of a photo, and iOS SandBox doesn't allow apps to delete user's assets as well, which makes deleting users photos almost impossible. All photos saved in iOS device follows the same naming system: "IMG_001.jpg", which makes it impossible to detect whether a photo is a screenshot from their names.
But apparently, this app implemented both functions. Does anyone have any ideas about this?
Thanks!
You can check using PHAsset's mediaSubtypes property.
let types = phAsset.mediaSubtypes /// phAsset is a PHAsset
let isScreenshot = types.contains(.photoScreenshot) /// true if is screenshot
For screenshot, its UTI is always a "public.png" and same size as screen (be sure you have multiply [UIScreen scale] on screen bounds width and height), just need to check these 2 metadata, you can easily identify screenshot.
Hope this will helps you
we are having problems with image not showing up on the apple watch, we tried the following :
Our image is located in the apple watchkit extension, and we tried to put it in the cache:
let img = UIImage(named:"slider_r.png")
WKInterfaceDevice().addCachedImage(img!, name:"slider_r.png")
It crashed immediately...
Then we tried to add the image directly on the apple watchkit app: no assets.
No image loaded up...
Then we tried putting it in an image.assets didn't work either...
We are currently out of ideas...
Thanks !
Alright, I've been working with WatchKit for about a month now - here's what I know:
Placing your image into the Watch App's Assets Catalog will add it to the Watch's bundle. This will be immediately available for use using UIImage's .setImageNamed("name").
Placing your image into the Watch Extension's Assets Catalog will add it to the extension's bundle, residing on the phone. Now, to get that to the watch you have to first grab a reference to the image from the extension, then add it to the device's cache, using WKInterfaceDevice().addCachedImage(image, name:).
Check out the Apple documentation for providing images to the Watch here. Here's the documentation for setImage(_ image: UIImage?):
This method changes the image being displayed. Use this method to send images from your WatchKit extension to the WatchKit app. The image interface object is resized to accommodate the size of the newly specified image. If the image itself is too large for the device’s screen, the image is clipped.
This is not what you want. You want to explicitly add the image to the cache so you can use it later. If you use setImage as described above, it will transfer the image from the phone to the watch every time you call it, which is not ideal if you're using the same image in multiple locations or you're using it very frequently. You have to be careful in choosing exactly which images you want to cache on the watch.
Using what we now know:
var img: UIImage = UIImage(named: "slider_r") // grabs the image from extension's bundle
WKInterfaceDevice().addCachedImage(img!, named: "slider_r") // adds to the Watch cache
myImageOutlet.setImageNamed("slider_r") // grabs the image from the Watch cache
Ensure that the asset catalog is included in the extension's target so that the images are correctly placed in the bundle at runtime.
You do not need to include the extension (e.g. ".png") in the image's name.
What I try to achieve is to take a photo and let the user specify if the photo belongs to category 1 or category 2. I have 2 buttons, one for each category. When the user presses the button, the photo is saved to the camera roll. AFterwards, at home, when I sync my iPad with iPhoto, I want to be able to sort by category, or at least identify to with category it belongs...
I first thought of the following :
1) taking a photo using the iPad camera -- this is already done in my app
2) saving the photo in camera roll under a specific name, such as cat1_pict123.jpg or cat2_pict456.jpg
I would plan to use
UIImageWriteToSavedPhotosAlbum(myImage, nil, nil, nil );
but I don't know how / or if it is possible to specify a file name ?
Alternatively, is there a way to "tag" a photo before saving it to camera roll ? A comment or something else, which will be visible in iPhoto ?
Thank you for your help
You can't use file names for images saved in photolibrary.
Save that to Document directory with specific name.
There is a way to kinda do that, by setting the image IPTC metadata:
Set the field "Object Name" to set the image title in
iPhoto.
Set the field "Keywords" to set the keywords in
iPhoto, then use a smart album to see all the images with these
keywords.
See details (and code) at http://ootips.org/yonat/how-to-set-the-image-name-when-saving-to-the-camera-roll/ .
That's not possible right now.