[MonoTouch] writing a photo (jpeg) to Photo Album

Craig Dunn craig.dunn at conceptdevelopment.net
Wed Mar 7 21:41:59 UTC 2012


UIImagePicker doco<https://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerControllerDelegate_Protocol/UIImagePickerControllerDelegate/UIImagePickerControllerDelegate.html#//apple_ref/occ/intfm/UIImagePickerControllerDelegate/imagePickerController:didFinishPickingMediaWithInfo:>says

UIImagePickerControllerMediaMetadata

Metadata for a newly-captured photograph.

The value for this key is an
NSDictionary<https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/Reference/Reference.html#//apple_ref/occ/cl/NSDictionary>
object
that contains the metadata of the photo that was just captured. To store
the metadata along with the image in the Camera Roll, use the
writeImageToSavedPhotosAlbum:metadata:completionBlock:<https://developer.apple.com/library/ios/documentation/AssetsLibrary/Reference/ALAssetsLibrary_Class/Reference/Reference.html#//apple_ref/occ/instm/ALAssetsLibrary/writeImageToSavedPhotosAlbum:metadata:completionBlock:>
method
of the Assets Library framework.


Here is a quick sample - the metadata is definitely preserved (
http://imgur.com/rV2SV). notice, however, the fileinfo on the right - that
photo was captured and saved with an empty NSDictionary - so "The image
already has embedded metadata" isn't really true (ie. UIImage only contains
image data, the metadata comes back from the camera separately).


cameraButton = UIButton.FromType (UIButtonType.RoundedRect);

cameraButton.Frame = new RectangleF(10, 320, 60,30);

cameraButton.SetTitle ("Camera", UIControlState.Normal);

cameraButton.TouchUpInside += (sender, e) => {

//
https://raw.github.com/migueldeicaza/TweetStation/master/TweetStation/UI/Camera.cs

 TweetStation.Camera.TakePicture (this, (obj) =>{

//
https://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerControllerDelegate_Protocol/UIImagePickerControllerDelegate/UIImagePickerControllerDelegate.html#//apple_ref/occ/intfm/UIImagePickerControllerDelegate/imagePickerController:didFinishPickingMediaWithInfo
:

var photo = obj.ValueForKey(new NSString(
"UIImagePickerControllerOriginalImage")) as UIImage;

var meta = obj.ValueForKey(new NSString(
"UIImagePickerControllerMediaMetadata")) as NSDictionary;


 ALAssetsLibrary library = new ALAssetsLibrary();

// parameters need to be prepared here

 library.WriteImageToSavedPhotosAlbum (photo.CGImage, meta, (assetUrl,
error) =>{

Console.WriteLine ("assetUrl:"+assetUrl);

} );

} );

};

View.Add (cameraButton);



HTH
cd


On Thu, Mar 8, 2012 at 6:21 AM, Jason Awbrey <jason at awbrey.net> wrote:

> according to the docs, the tags in the Dictionary you pass in will get
> merged with any tags already embedded in the image.  If there is a conflict
> the new tags in the dictionary overwrite the tags already embedded in the
> image
>
> On Wed, Mar 7, 2012 at 12:12 PM, jGoff <info at goffs.net> wrote:
>
>> Does anyone have a code snippet the shows how to use the ALAssetsLibrary
>> class for saving a JPEG file.  I previously used the SaveToPhotosAlbum
>> method in UIImage, but since it does not preserve the embedded metadata,
>> I'm
>> pretty sure I have to switch to WriteImageToSavedPhotosAlbum.  The
>> beginning
>> would be:
>>
>> using MonoTouch.AssetsLibrary;
>> ...
>> ALAssetsLibrary library = new ALAssetsLibrary();
>>
>> // parameters need to be prepared here
>>
>> library.WriteImageToSavedPhotosAlbum(
>>
>> --------------------------------------------------------------
>>
>> But then what?  I'm a little confused that it wants me to pass in the
>> metadata.  The image already has embedded metadata.  Do I have have to
>> extract it, so I can pass it back in?  Also since it indicates that using
>> imageData of Type UIImage is obsolete, which is the correct Type?
>>
>> Assistance doing this seemingly simple task would be greatly appreciated.
>> Thanks.
>>
>>
>> --
>> View this message in context:
>> http://monotouch.2284126.n4.nabble.com/writing-a-photo-jpeg-to-Photo-Album-tp4454061p4454061.html
>> Sent from the MonoTouch mailing list archive at Nabble.com.
>> _______________________________________________
>> MonoTouch mailing list
>> MonoTouch at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/monotouch
>>
>
>
> _______________________________________________
> MonoTouch mailing list
> MonoTouch at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/monotouch
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/monotouch/attachments/20120308/a0d53b06/attachment-0001.html>


More information about the MonoTouch mailing list