当前位置: 首页>>代码示例>>C#>>正文


C# UIImage.AsPNG方法代码示例

本文整理汇总了C#中UIImage.AsPNG方法的典型用法代码示例。如果您正苦于以下问题:C# UIImage.AsPNG方法的具体用法?C# UIImage.AsPNG怎么用?C# UIImage.AsPNG使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UIImage的用法示例。


在下文中一共展示了UIImage.AsPNG方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SaveImageToTemporaryFilePng

		/// <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;
		}
开发者ID:ChristianJaspers,项目名称:saapp-ios,代码行数:31,代码来源:ImageFilesManagementHelper.cs

示例2: SerializeImage

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

            return image.AsJPEG (JpegCompressionQuality);
        }
开发者ID:stampsy,项目名称:Stampsy.ImageSource,代码行数:7,代码来源:ScaledSource.cs

示例3: UploadImage

		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;
		}
开发者ID:MavenRain,项目名称:IOSAzureBlobUploader,代码行数:13,代码来源:RootViewController.cs

示例4: ImageData

		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 ());
			}
		}
开发者ID:stampsy,项目名称:Xamarin.Social,代码行数:22,代码来源:ImageData.cs

示例5: AddToCache

        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);
                }
            }
        }
开发者ID:EeKay,项目名称:UrlImageStore,代码行数:20,代码来源:UrlImageStore.cs

示例6: OpenLine

        /// <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);
         }
开发者ID:CH3COOH,项目名称:Softbuild.Social.Line,代码行数:20,代码来源:LineOpener.cs

示例7: Save

        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");
            }
        }
开发者ID:janeC,项目名称:sysdrawing-coregraphics,代码行数:29,代码来源:Bitmap.cs

示例8: AddToCache

        /// <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);
                }
            }
        }
开发者ID:vancura,项目名称:vancura-cs-libs,代码行数:23,代码来源:UrlImageStore.cs

示例9: Log

        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 );
                }
            }
        }
开发者ID:lachlanroche,项目名称:monotouch-nslogger,代码行数:19,代码来源:NSLogger.cs

示例10: PostNewAvatar

        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 ();
                    });
                }
            });
        }
开发者ID:bholmes,项目名称:XamarinEvolve2013Project,代码行数:16,代码来源:ProfileViewController.cs

示例11: SaveImage

        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]{ "", "" };
        }
开发者ID:Skalar,项目名称:Indexer,代码行数:36,代码来源:ImagePanel.cs

示例12: Save

		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);
		}
开发者ID:modulexcite,项目名称:artapp,代码行数:9,代码来源:ImageCache.cs

示例13: GetImageStream

//        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();
        }
开发者ID:robbie99,项目名称:acr-xamarin-forms,代码行数:13,代码来源:SignatureServiceController.cs

示例14: SaveTemporaly

        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;
        }
开发者ID:jhenier13,项目名称:StudyCards,代码行数:17,代码来源:ImageDrawingView.cs


注:本文中的UIImage.AsPNG方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。