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


C# UIImage.AsJPEG方法代码示例

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


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

示例1: 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

示例2: AsImage

 public static DumpValue AsImage(UIImage image)
 {
     var data = image.AsJPEG(0.6f);
     var dataBytes = new byte[data.Length];
     System.Runtime.InteropServices.Marshal.Copy(data.Bytes, dataBytes, 0, Convert.ToInt32(data.Length));
     return new DumpValue { TypeName = "___IMAGE___", DumpType = DumpValue.DumpTypes.Image, PrimitiveValue = Convert.ToBase64String(dataBytes) };
 }
开发者ID:tluyben,项目名称:ProtoPad,代码行数:7,代码来源:ObjectDumper.cs

示例3: HandleImagePick

		private void HandleImagePick(UIImage image, int maxPixelDimension, int percentQuality, 
                                         Action<Stream> pictureAvailable, Action assumeCancelled)
		{
			if (image != null)
			{
				// resize the image
				image = image.ImageToFitSize (new SizeF (maxPixelDimension, maxPixelDimension));
				
				using (NSData data = image.AsJPEG ((float)((float)percentQuality/100.0)))
				{
					var byteArray = new byte [data.Length];
					Marshal.Copy (data.Bytes, byteArray, 0, Convert.ToInt32 (data.Length));
					
					var imageStream = new MemoryStream ();
					imageStream.Write (byteArray, 0, Convert.ToInt32 (data.Length));
					imageStream.Seek (0, SeekOrigin.Begin);
					
					pictureAvailable (imageStream);
				}
			}
			else
			{
				assumeCancelled ();
			}
			
			_picker.DismissModalViewControllerAnimated(true);
			_presenter.NativeModalViewControllerDisappearedOnItsOwn();
				
		}
开发者ID:Gert-Cominotto,项目名称:MvvmCross,代码行数:29,代码来源:MvxImagePickerTask.cs

示例4: SaveImageToTemporaryFileJpeg

		public async Task<string> SaveImageToTemporaryFileJpeg(UIImage image, float quality = 1.0f)
		{
			var uniqueFileNamePortion = Guid.NewGuid().ToString();
			var temporaryImageFileName = string.Format("{0}.jpg", uniqueFileNamePortion);

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

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

			var imageData = image.AsJPEG(quality);
			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,代码行数:26,代码来源:ImageFilesManagementHelper.cs

示例5: ImageToByteArray

 public static void ImageToByteArray(UIImage image, out byte[] mediaByteArray)
 {
     using (NSData imgData = image.AsJPEG ())
     {
         mediaByteArray = new byte[imgData.Length];
         System.Runtime.InteropServices.Marshal.Copy (imgData.Bytes, mediaByteArray, 0, Convert.ToInt32 (imgData.Length));
     }
     image.Dispose ();
 }
开发者ID:shuoguo,项目名称:cross-copy,代码行数:9,代码来源:iOSHelpers.cs

示例6: getSignatureString

        private string getSignatureString(UIImage signatureImage)
        {
            NSData signatureData = signatureImage.AsJPEG();

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

            return System.Convert.ToBase64String(signatureByteArray);
        }
开发者ID:bertouttier,项目名称:ExpenseApp-Mono,代码行数:9,代码来源:SignController.cs

示例7: ExportToJpg

        public static byte[] ExportToJpg(UIImage image)
        {
            using (NSData data = image.AsJPEG(1)) {
                byte[] binaryData = new byte[data.Length];

                // Copy the unmanaged data hold by the NSData to a new managed byte array.
                System.Runtime.InteropServices.Marshal.Copy(data.Bytes, binaryData, 0, (int)data.Length);

                return binaryData;
            }
        }
开发者ID:rFlex,项目名称:Monotouch-Upload-Showcase,代码行数:11,代码来源:TestUploadViewController.cs

示例8: FinishedPickingImage

        public override void FinishedPickingImage(UIImagePickerController picker, UIImage image, NSDictionary editingInfo)
        {
            // Here you can do anything with the image... save for example.
            var documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            string jpgFilename = System.IO.Path.Combine(documentsDirectory, string.Format("{0}.jpg", Guid.NewGuid()));

            using (NSData imageData = image.AsJPEG(0.2f))
            {
                NSError err;
                if (!imageData.Save(jpgFilename, false, out err))
                {
                    Console.WriteLine("Saving of file failed: " + err.Description);
                }
            }
        }
开发者ID:GiusepeCasagrande,项目名称:XamarinSimpleCameraSample,代码行数:15,代码来源:ImagePickerDelegate.cs

示例9: 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:RJInfotech,项目名称:Xamarin.Social,代码行数:22,代码来源:ImageData.cs

示例10: SendTo

        /// <summary>
        /// Sends the specified UIImage to the AirPlay device.
        /// </summary>
        /// <param name='service'>
        /// NSNetService (extension method target) representing the AirPlay device.
        /// </param>
        /// <param name='image'>
        /// The UIImage to be send to the device.
        /// </param>
        /// <param name='complete'>
        /// Optional method to be called when the operation is complete. True will be supplied if the action was
        /// successful, false if a problem occured.
        /// </param>
        public static unsafe void SendTo(this NSNetService service, UIImage image, Action<bool> complete)
        {
            if (service == null) {
                if (complete != null)
                    complete (false);
                return;
            }

            // In general I prefer WebClient *Async methods but it does not provide methods to
            // upload Stream and allocating a (not really required) byte[] is a huge waste
            ThreadPool.QueueUserWorkItem (delegate {
                bool ok = true;
                try {
                    string url = String.Format ("http://{0}:{1}/photo", service.HostName, service.Port);
                    HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url);
                    using (var data = image.AsJPEG ()) {
                        req.Method = "PUT";
                        req.ContentLength = data.Length;
                        req.UserAgent = "AirPlay/160.4 (Photos)";
                        req.Headers.Add ("X-Apple-AssetKey", Guid.NewGuid ().ToString ());
                        req.Headers.Add ("X-Apple-Session-ID", session.ToString ());
                        var s = req.GetRequestStream ();
                        using (Stream ums = new UnmanagedMemoryStream ((byte *) data.Bytes, data.Length))
                            ums.CopyTo (s);
                    }
                    req.GetResponse ().Dispose ();
                }
                catch {
                    ok = false;
                }
                finally {
                    if (complete != null) {
                        NSRunLoop.Main.InvokeOnMainThread (delegate {
                            complete (ok);
                        });
                    }
                }
            });
        }
开发者ID:dancingalone,项目名称:airplay,代码行数:52,代码来源:AirPlayRocks.cs

示例11: GetImageIntoCache

        public void GetImageIntoCache(NSAction doWhenDone)
        {
            if (image == null)
            {
                if (CachedThumbExists(Program.ProgramId))
                {

                    image = UIImage.FromFileUncached(CachedThumbFullpath(Program.ProgramId));
                } else
                {

                    using (NSData imgData = NSData.FromUrl(new NSUrl(Program.ThumbnailUrl)))
                    {
                        using (UIImage tempimage = UIImage.LoadFromData(imgData))
                        {
                            image = ImageHelper.ResizeImage(tempimage, -1, 35);
                            NSData data = image.AsJPEG();
                            NSError error;
                            data.Save(CachedThumbFullpath(Program.ProgramId), false, out error);

                        }
                    }
                }
            }

            doWhenDone();
        }
开发者ID:nicwise,项目名称:onthetelly,代码行数:27,代码来源:RemoteProgramHelper.cs

示例12: 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

示例13: SaveImage

		public void SaveImage(UIImage image)
		{
			_imagePicked = true;

			string filepath = Path.Combine(Environment.GetFolderPath (Environment.SpecialFolder.Personal), _filename);
			   
			using (NSData imageData = image.AsJPEG())
			{
				NSError err = new NSError();
				imageData.Save(filepath, true, out err);
			}
			imageView.Image = image;
			
			loadView.StopAnimating();
			InitBarButtons();
			_callback(this);
			
			this.DismissModalViewControllerAnimated(true);
		}
开发者ID:darkwood,项目名称:Jaktloggen,代码行数:19,代码来源:FieldImagePickerScreen.xib.cs

示例14: save

        void save()
        {
            using (new NSAutoreleasePool())
            {
                NSError error = new NSError();
                selectedImage = Graphics.PrepareForUpload(selectedImage);
                selectedImage.AsJPEG().Save(Path.Combine(Util.PicDir,Value),NSDataWritingOptions.Atomic,out error);
                NSObject invoker = new NSObject();
                invoker.InvokeOnMainThread(delegate {
                    completed();
                });

            }
        }
开发者ID:Clancey,项目名称:WcfTestSuite,代码行数:14,代码来源:ImagePickerElement.cs

示例15: SendImage

    private async void SendImage(UIImage image)
    {
      try
      {
        using (ISitecoreWebApiSession session = this.instanceSettings.GetSession())
        {
          Stream stream = image.AsJPEG().AsStream();

          var request = ItemWebApiRequestBuilder.UploadResourceRequestWithParentPath(itemPathTextField.Text)
            .ItemDataStream(stream)
            .ContentType("image/jpg")
            .ItemName(this.itemNameTextField.Text)
            .FileName("imageFile.jpg")
            .Build();

          this.ShowLoader();

          var response = await session.UploadMediaResourceAsync(request);

          if (response != null)
          {
            AlertHelper.ShowAlertWithOkOption("upload image result","The image uploaded successfuly");
          }
          else
          {
            AlertHelper.ShowAlertWithOkOption("upload image result","something wrong");
          }
        }
      }
      catch(Exception e) 
      {
        AlertHelper.ShowLocalizedAlertWithOkOption("Error", e.Message);
      }
      finally
      {
        BeginInvokeOnMainThread(delegate
        {
          this.HideLoader();
        });
      }
    }
开发者ID:amatkivskiy,项目名称:sitecore-xamarin-pcl-sdk,代码行数:41,代码来源:UploadImageViewController.cs


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