/// <summary>
		/// Saves the image to temporary file in png format.
		/// </summary>
		/// <returns>Path to temporary file representing image provide as paramater</returns>
		/// <param name="image">The image to be saved to a tempoarary png file</param>
		public async Task<string> SaveImageToTemporaryFilePng(UIImage image)
		{
			var uniqueFileNamePortion = Guid.NewGuid().ToString();
			var temporaryImageFileName = string.Format("{0}.png", uniqueFileNamePortion);

			var documentsFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
			var temporaryStorageFolderPath = Path.Combine(documentsFolderPath, "..", "tmp");

			var temporaryImageFilePath = Path.Combine(temporaryStorageFolderPath, temporaryImageFileName);

			var imageData = image.AsPNG();
			await Task.Run(() => 
			{
				//File.WriteAllBytes(temporaryImageFilePath, imageData);
				NSError error = null;
				if (imageData.Save(temporaryImageFilePath, false, out error)) 
				{
					Console.WriteLine("Saved image to temporary file: " + temporaryImageFilePath);
				} else 
				{
					Console.WriteLine("ERROR! Did NOT SAVE file because" + error.LocalizedDescription);
				}
			});

			return temporaryImageFilePath;
		}
        NSData SerializeImage (UIImage image, string typeIdentifier)
        {
            if (typeIdentifier == "public.png")
                return image.AsPNG ();

            return image.AsJPEG (JpegCompressionQuality);
        }
		private CloudBlockBlob UploadImage(UIImage image, String name) 
		{
			var client = GetClient ();
			var container = client.GetContainerReference("images");
			container.CreateIfNotExists();
			var blob = container.GetBlockBlobReference(name);
			var pngImage = image.AsPNG ();
			var stream = pngImage.AsStream();

			blob.UploadFromStream (stream);

			return blob;
		}
Example #4
0
		public ImageData (UIImage image, string filename)
		{
			if (image == null) {
				throw new ArgumentNullException ("image");
			}
			if (string.IsNullOrEmpty (filename)) {
				throw new ArgumentException ("filename");
			}

			Image = image;
			Filename = filename;

			MimeType = (filename.ToLowerInvariant ().EndsWith (".png")) ?
				"image/png" : "image/jpeg";

			if (MimeType == "image/png") {
				Data = new NSDataStream (image.AsPNG ());
			}
			else {
				Data = new NSDataStream (image.AsJPEG ());
			}
		}
Example #5
0
        internal void AddToCache(string id, UIImage img)
        {
            string file = picDir + GenerateMD5 (id) + ".png";

            if (!File.Exists(file))
            {
                //Save it to disk
                NSError err = null;
                try
                {
                    img.AsPNG().Save(file, false, out err);
                    if (err != null)
                        Console.WriteLine(err.Code.ToString() + " - " + err.LocalizedDescription);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
                }
            }
        }
        /// <summary>
        /// Opens the line.
        /// </summary>
        /// <returns><c>true</c>, if line was opened, <c>false</c> otherwise.</returns>
        /// <param name="image">Image.</param>
        public static bool OpenLine(UIImage image)
        {
            if (!CanOpenLine())
                return false;

            var pasteboard = UIPasteboard.GetUnique();
            pasteboard.SetData(image.AsPNG(), "public.png");

            var pasteboardName = pasteboard.Name;
            var encoded = Uri.EscapeDataString(pasteboardName);
            var url = CreateNSUrl(LineUrlContentTypes.Image, encoded);

            var shareApp = UIApplication.SharedApplication;
            return shareApp.OpenUrl(url);
         }
Example #7
0
        public void Save(string path, ImageFormat format)
        {
            if (path == null)
                throw new ArgumentNullException ("path");

            if (NativeCGImage == null)
                throw new ObjectDisposedException ("cgimage");

            using (var uiimage = new UIImage (NativeCGImage)){
                NSError error;

                if (format == ImageFormat.Jpeg){
                    using (var data = uiimage.AsJPEG ()){
                        if (data.Save (path, NSDataWritingOptions.Atomic, out error))
                            return;

                        throw new IOException ("Saving the file " + path + " " + error);
                    }
                } else if (format == ImageFormat.Png){
                    using (var data = uiimage.AsPNG ()){
                        if (data.Save (path, NSDataWritingOptions.Atomic, out error))
                            return;

                        throw new IOException ("Saving the file " + path + " " + error);
                    }
                } else
                    throw new ArgumentException ("Unsupported format, only Jpeg and Png are supported", "format");
            }
        }
Example #8
0
        /// <summary>
        /// Adds to cache.
        /// </summary>
        /// <param name="id">Identifier.</param>
        /// <param name="img">Image.</param>
        internal void AddToCache(string id, UIImage img)
        {
            string cachedFilename = cachedImageDir + "/" + StringUtils.GenerateMD5 (id) + ".png";

            if (!File.Exists (cachedFilename)) {
                // save it to disk
                NSError err = null;

                try {
                    img.AsPNG ().Save (cachedFilename, false, out err);

                    if (err != null)
                        Console.WriteLine ("UrlImageStore: Error encoding file {0} to cache ({1} - {2})", cachedFilename, err.Code.ToString (), err.LocalizedDescription);
                } catch (Exception ex) {
                    Console.WriteLine ("UrlImageStore: Error encoding file {0} to cache ({1})\n{2}", cachedFilename, ex.Message, ex.StackTrace);
                }
            }
        }
        public void Log( string tag, int level, UIImage image )
        {
            if (image == null) {
                throw new ArgumentNullException("image");
            }

            NSString ns_tag = null;
            IntPtr ptr_tag = IntPtr.Zero;
            if (tag != null) {
                ns_tag = new NSString(tag);
                ptr_tag = ns_tag.Handle;
            }

            using (ns_tag) {
                using (var png = image.AsPNG()) {
                    LogImageData( logger, ptr_tag, level, (int) image.Size.Width, (int) image.Size.Height, png.Handle );
                }
            }
        }
        void PostNewAvatar(UIImage image)
        {
            NSData data = image.AsPNG ();

            byte[] dataBytes = new byte[data.Length];
            System.Runtime.InteropServices.Marshal.Copy(data.Bytes, dataBytes, 0, Convert.ToInt32(data.Length));

            Engine.Instance.AvatarAccess.PostNewAvatar (dataBytes, (result) => {
                if (result.Exceptin != null)
                {
                    _controller.BeginInvokeOnMainThread (delegate {
                        _controller.RefreshHeaderCell ();
                    });
                }
            });
        }
Example #11
0
        public static string[] SaveImage(string name, UIImage ourpic)
        {
            if (ourpic == null)
                return new string[2]{ "", "" };
            Console.WriteLine ("Save");
            UIImage thumbPic = ourpic.Scale (new SizeF (50, 50)); //measurements taken from CustomCell, alternatly 33x33

            if (ourpic != null) {
                var documentsDirectory = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
                var picname = name + ".png";
                var thumbpicname = name + "_thumb.png";
                string pngfileName = System.IO.Path.Combine (documentsDirectory, picname);
                string thumbpngfileName = System.IO.Path.Combine (documentsDirectory, thumbpicname);
                NSData imgData = ourpic.AsPNG ();
                NSData img2Data = thumbPic.AsPNG ();

                NSError err = null;
                if (imgData.Save (pngfileName, false, out err)) {
                    Console.WriteLine ("saved as " + pngfileName);
                } else {
                    Console.WriteLine ("NOT saved as " + pngfileName + " because" + err.LocalizedDescription);
                }

                err = null;
                if (img2Data.Save (thumbpngfileName, false, out err)) {
                    Console.WriteLine ("saved as " + thumbpngfileName);
                    string[] result = new string[2] { picname, thumbpicname };
                    return result;

                } else {
                    Console.WriteLine ("NOT saved as " + thumbpngfileName + " because" + err.LocalizedDescription);
                    return null;
                }
            }
            return new string[2]{ "", "" };
        }
Example #12
0
		public static void Save(string path, UIImage image)
		{
			if(File.Exists(path))
			{
				File.Delete(path);	
			}
			NSError err = null;
			image.AsPNG().Save(path, true, out err);
		}
//        public override void TouchesBegan(NSSet touches, UIEvent evt) {
//            base.TouchesBegan(touches, evt);
//            if (this.onResult == null)
//                this.DismissViewController(true, null);
//        }


        private static Stream GetImageStream(UIImage image, ImageFormatType formatType) {
            if (formatType == ImageFormatType.Jpg)
                return image.AsJPEG().AsStream();

            return image.AsPNG().AsStream();
        }
Example #14
0
        private string SaveTemporaly(UIImage image)
        {
            if (string.IsNullOrEmpty(IMAGE_FILE_NAME))
            {
                DirectoryInfo tempDir = new DirectoryInfo(EnviromentDirectories.IOS_TEMP_DIRECTORY);
                FileInfo[] tempFiles = tempDir.GetFiles();
                IMAGE_FILE_NAME = string.Format("{0}({1}).png", TEMP_IMAGE_NAME, tempFiles.Length);
            }

            string tempImagePath = Path.Combine(EnviromentDirectories.IOS_TEMP_DIRECTORY, IMAGE_FILE_NAME);

            NSData imageData = image.AsPNG();
            NSError error = null;
            imageData.Save(tempImagePath, false, out error);

            return tempImagePath;
        }