partial void ResizePhotoButton_TouchUpInside(UIButton sender) { //Scale to largest needed Profile pic size profileImage = originalImage.Scale(new CGSize(300, 300)); //Scale to largest needed Event pic size eventImage = originalImage.Scale(new CGSize(960, 708)); //Merge the two photos into one in order to view both sizes on the screen UIGraphics.BeginImageContext(new CGSize(960, 1008)); profileImage.Draw(new CGRect(0, 0, 300, 300)); eventImage.Draw(new CGRect(0, 300, 960, 708)); var combinedImage = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); PhotoPreview.Image = combinedImage; //Save photos, adapted from another project. Will save each size indiviually var documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); var profileFileName = System.IO.Path.Combine(documentsDirectory, "profile.jpg"); var eventFileName = System.IO.Path.Combine(documentsDirectory, "event.jpg"); NSError error = null; if (profileImage.AsJPEG().Save(profileFileName, false, out error)) { Console.WriteLine("File written to : {0}", profileFileName); } if (eventImage.AsJPEG().Save(eventFileName, false, out error)) { Console.WriteLine("File written to : {0}", eventFileName); } }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); try { if (!string.IsNullOrEmpty(backgroundImage)) { UIImage i = UIImage.FromFile(backgroundImage); var size = new CoreGraphics.CGSize(0, 0); if (CoreSettings.ScreenSize != null) { size.Height = (nfloat)CoreSettings.ScreenSize.Height; size.Width = (nfloat)CoreSettings.ScreenSize.Width; } if (size.Height > this.View.Frame.Size.Height) { UIGraphics.BeginImageContext(size); i = i.Scale(size); } else { UIGraphics.BeginImageContext(this.View.Frame.Size); i = i.Scale(this.View.Frame.Size); } this.View.BackgroundColor = UIColor.FromPatternImage(i); } } catch (Exception ex) { ex.ConsoleWrite(); } if (this.NavigationController != null) { var isVisible = !this.NavigationController.TopViewController.NavigationItem.HidesBackButton; if (isVisible && basePage != null && basePage.OverrideBackButton) { this.NavigationController.TopViewController.NavigationItem.SetHidesBackButton(true, false); // Change back icon. this.NavigationController.TopViewController.NavigationItem.LeftBarButtonItem = new UIBarButtonItem( basePage.OverrideBackText, UIBarButtonItemStyle.Plain, (sender, args) => { if (basePage.NeedOverrideSoftBackButton) { basePage.OnSoftBackButtonPressed(); } else { NavigationController.PopViewController(true); } }); } } }
/// <summary> /// Loads an image from a bundle given the supplied image name, resizes it to the /// height and width request and sets it into a <see cref="UIButton" />. /// </summary> /// <param name="source">The <see cref="ImageSource" /> to load the image from.</param> /// <param name="widthRequest">The requested image width.</param> /// <param name="heightRequest">The requested image height.</param> /// <param name="targetButton">A <see cref="UIButton" /> to set the image into.</param> /// <param name="state">The state.</param> /// <param name="tintColor">Color of the tint.</param> /// <returns>A <see cref="Task" /> for the awaited operation.</returns> private async static Task SetImageAsync(ImageSource source, int widthRequest, int heightRequest, UIButton targetButton, UIControlState state = UIControlState.Normal, UIColor tintColor = null) { var handler = GetHandler(source); using (UIImage image = await handler.LoadImageAsync(source)) { if (image == null) { return; } UIImage scaled = image; if (heightRequest > 0 && widthRequest > 0 && (image.Size.Height != heightRequest || image.Size.Width != widthRequest)) { scaled = scaled.Scale(new CGSize(widthRequest, heightRequest), 3); } if (tintColor != null) { targetButton.TintColor = tintColor; targetButton.SetImage(scaled.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate), state); } else { targetButton.SetImage(scaled.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), state); } } }
internal static async Task <StorageItemThumbnail> CreateVideoThumbnailAsync(StorageFile file) { AVAsset asset = AVUrlAsset.FromUrl(NSUrl.FromFilename(file.Path)); AVAssetImageGenerator generator = AVAssetImageGenerator.FromAsset(asset); generator.AppliesPreferredTrackTransform = true; NSError error; CMTime actualTime; CMTime time = CMTime.FromSeconds(asset.Duration.Seconds / 2, asset.Duration.TimeScale); CGImage image = generator.CopyCGImageAtTime(time, out actualTime, out error); #if __MAC__ NSMutableData buffer = new NSMutableData(); CGImageDestination dest = CGImageDestination.Create(buffer, UTType.JPEG, 1, null); dest.AddImage(image); return(new StorageItemThumbnail(buffer.AsStream())); #else UIImage image2 = UIImage.FromImage(image); image.Dispose(); UIImage image3 = image2.Scale(new CGSize(240, 240)); image2.Dispose(); return(new StorageItemThumbnail(image3.AsJPEG().AsStream())); #endif }
internal static async Task <StorageItemThumbnail> CreatePhotoThumbnailAsync(StorageFile file) { #if __MAC__ NSImage image = NSImage.FromStream(await file.OpenStreamForReadAsync()); double ratio = image.Size.Width / image.Size.Height; NSImage newImage = new NSImage(new CGSize(240, 240 * ratio)); newImage.LockFocus(); image.Size = newImage.Size; image.Draw(new CGPoint(0, 0), new CGRect(0, 0, newImage.Size.Width, newImage.Size.Height), NSCompositingOperation.Copy, 1.0f); newImage.UnlockFocus(); NSMutableData buffer = new NSMutableData(); CGImageDestination dest = CGImageDestination.Create(buffer, UTType.JPEG, 1); dest.AddImage(newImage.CGImage); return(new StorageItemThumbnail(buffer.AsStream())); #else UIImage image = UIImage.FromFile(file.Path); UIImage image2 = image.Scale(new CGSize(240, 240)); image.Dispose(); return(new StorageItemThumbnail(image2.AsJPEG().AsStream())); #endif }
public override void ViewDidLoad() { base.ViewDidLoad(); if (this.NavigationItem.BackBarButtonItem != null) { this.NavigationItem.BackBarButtonItem.TintColor = new UIColor(1.0f, 1.0f, 1.0f, 1.0f); this.NavigationItem.BackBarButtonItem.Title = " "; } // this.NavigationController.SetNavigationBarHidden(true, true); UIImage image = UIImage.FromBundle("Background.jpg"); image = image.Scale(new System.Drawing.SizeF(320f, 580f)); this.View.BackgroundColor = UIColor.FromPatternImage(image); //this.NavigationController.NavigationBar.SetBackgroundImage(image, UIBarMetrics.Default); // this.NavigationController.NavigationBaZr.Alpha = 0.1f; ConnectToServer(); btnLogin.TouchUpInside += LoginBtnClick; txtUsername.ShouldReturn += JumptoPassword; txtPassword.ShouldReturn += LoginReturn; }
public static Texture2D FromFile(GraphicsDevice graphicsDevice, string filename, int width, int height) { UIImage image = UIImage.FromBundle(filename); if (image == null) { throw new ContentLoadException("Error loading file: " + filename); } ESImage theTexture; if (width == 0 && height == 0) { theTexture = new ESImage(image, graphicsDevice.PreferedFilter); } else { var small = image.Scale(new SizeF(width, height)); theTexture = new ESImage(small, graphicsDevice.PreferedFilter); } Texture2D result = new Texture2D(theTexture); // result.Name = Path.GetFileNameWithoutExtension(filename); result.Name = filename; return(result); }
public static CVPixelBuffer ToCVPixelBuffer(this UIImage image, CGSize size) { var attrs = new CVPixelBufferAttributes { CGImageCompatibility = true, CGBitmapContextCompatibility = true }; var cgImg = image.Scale(size).CGImage; var pb = new CVPixelBuffer(cgImg.Width, cgImg.Height, CVPixelFormatType.CV32ARGB, attrs); pb.Lock(CVPixelBufferLock.None); var pData = pb.BaseAddress; var colorSpace = CGColorSpace.CreateDeviceRGB(); var ctxt = new CGBitmapContext(pData, cgImg.Width, cgImg.Height, 8, pb.BytesPerRow, colorSpace, CGImageAlphaInfo.NoneSkipFirst); ctxt.TranslateCTM(0, cgImg.Height); ctxt.ScaleCTM(1.0f, -1.0f); UIGraphics.PushContext(ctxt); image.Draw(new CGRect(0, 0, cgImg.Width, cgImg.Height)); UIGraphics.PopContext(); pb.Unlock(CVPixelBufferLock.None); return(pb); }
protected void OnCaptureComplete(object sender, UIImagePickerMediaPickedEventArgs e) { var mediaTypeString = e.Info[UIImagePickerController.MediaType].ToString(); if (string.Compare(mediaTypeString, "public.image", true) == -1) { return; } var referenceURL = e.Info[new NSString("UIImagePickerControllerReferenceUrl")] as NSUrl; if (referenceURL != null) { Console.WriteLine("Url:" + referenceURL.ToString()); } UIImage originalImage = e.Info[UIImagePickerController.OriginalImage] as UIImage; if (originalImage != null) { originalImage = originalImage.Scale(originalImage.Size, (nfloat)(originalImage .CurrentScale * 0.5)); var imageBytes = originalImage.AsJPEG().ToArray(); _imageTask.SetResult(imageBytes); } CancelCapture(); }
public override void ViewDidLoad() { base.ViewDidLoad(); nfloat w = View.Bounds.Width; nfloat h = View.Bounds.Height; int cellh = Convert.ToInt32((h - 182) / 6); View.BackgroundColor = UIColor.White; UIGraphics.BeginImageContext(this.View.Frame.Size); UIImage i = UIImage.FromBundle("Splash"); i = i.Scale(this.View.Frame.Size); View.BackgroundColor = UIColor.FromPatternImage(i); for (int j = 0; j < Config.data._deals.Count; j++) { int y = 100 + j * cellh; DealObject d = Config.data._deals[j]; UIButton btnDeal = UIButton.FromType(UIButtonType.Custom); btnDeal.Frame = new CoreGraphics.CGRect(20, y, 128, cellh); btnDeal.SetImage((UIImage)d.BMP, UIControlState.Normal); btnDeal.Tag = j; btnDeal.TouchUpInside += btnDeal_TouchUpInside; View.AddSubview(btnDeal); UILabel lblTitle = new UILabel(new CoreGraphics.CGRect(150, y, w - 170, cellh)); lblTitle.Lines = 3; lblTitle.Text = d.Title; View.AddSubview(lblTitle); } }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ public void UpdateView() { if (image != null) { if (UIScreen.MainScreen.Bounds.Width < UIScreen.MainScreen.Bounds.Height) { TimeLabel.Frame = new CoreGraphics.CGRect(TimeLabel.Frame.X, 62, TimeLabel.Frame.Width, TimeLabel.Frame.Height); ImageButton.Frame = new CoreGraphics.CGRect(ImageButton.Frame.X, 77, ImageButton.Frame.Width, ImageButton.Frame.Height); } else { TimeLabel.Frame = new CoreGraphics.CGRect(TimeLabel.Frame.X, 62 - 33, TimeLabel.Frame.Width, TimeLabel.Frame.Height); ImageButton.Frame = new CoreGraphics.CGRect(ImageButton.Frame.X, 77 - 35, ImageButton.Frame.Width, ImageButton.Frame.Height); } nfloat scaleKoeff = (nfloat)Math.Min(UIScreen.MainScreen.Bounds.Width / image.Size.Width, (UIScreen.MainScreen.Bounds.Height - ImageButton.Frame.Y) / image.Size.Height); Console.WriteLine("W: " + image.Size.Width.ToString() + "H: " + image.Size.Height.ToString()); Console.WriteLine("scaleKoeff: " + scaleKoeff.ToString() + "H: " + (image.Size.Height * scaleKoeff).ToString()); ImageButton.SetBackgroundImage(image.Scale(new CoreGraphics.CGSize(image.Size.Width * scaleKoeff, image.Size.Height * scaleKoeff)), UIControlState.Normal); ImageButton.SizeToFit(); TimeLabel.Text = lastTime.ToString(); } }
void ImagePicker_FinishedPickingMedia(object sender, UIImagePickerMediaPickedEventArgs e) { if (e.Info[UIImagePickerController.MediaType].ToString() == "public.image") { UIImage originalImage = e.Info[UIImagePickerController.OriginalImage] as UIImage; if (originalImage != null) { var scaledImage = originalImage.Scale(new CGSize(300, 300)); var classifier = new ImageClassifier(); var coreImage = new CIImage(scaledImage); CVPixelBuffer buffer = new CVPixelBuffer(300, 300, CVPixelFormatType.CV32ARGB); UIGraphics.BeginImageContext(new CGSize(300, 300)); CIContext context = CIContext.FromContext(UIGraphics.GetCurrentContext(), null); context.Render(coreImage, buffer); UIGraphics.EndImageContext(); var output = classifier.GetPrediction(buffer, out NSError error); imgSelected.Image = scaledImage; lblResult.Text = $"This looks like: {output.ClassLabel}"; } } imagePicker.DismissModalViewController(true); }
public static UIImage ResizedImageIcon(UIImage image) { SizeF size = new SizeF(25.0f, 25.0f); UIImage newImage = image.Scale(size, 2.0f); return(newImage); }
public UIImage CreateSignatureImage(double printWidth) { UIImage image = null; CGSize size = Element.Bounds.Size.ToSizeF(); float width = (float)Element.Bounds.Width; float height = (float)Element.Bounds.Height; float scale = (float)printWidth / width; UIGraphics.BeginImageContext(size); using (CGContext context = UIGraphics.GetCurrentContext()) { context.SetFillColor(Color.White.ToCGColor()); context.SetStrokeColor(SignaturePad.DefaultStrokeColor.ToCGColor()); context.SetLineWidth(SignaturePad.DefaultStrokeWidth); context.SetLineJoin(CGLineJoin.Round); context.SetLineCap(CGLineCap.Round); context.AddPath(path); context.DrawPath(CGPathDrawingMode.Stroke); image = UIGraphics.GetImageFromCurrentImageContext(); image = image.Scale(new CGSize(printWidth, height * scale)); } UIGraphics.EndImageContext(); return(image); }
UIImage ScaledImage(UIImage image, nfloat maxWidth, nfloat maxHeight) { var maxResizeFactor = Math.Min(maxWidth / image.Size.Width, maxHeight / image.Size.Height); var width = maxResizeFactor * image.Size.Width; var height = maxResizeFactor * image.Size.Height; return(image.Scale(new CoreGraphics.CGSize(width, height))); }
public UIImage ScaleImageToSize(UIImage image, CGSize newSize) { double widthRatio = newSize.Width / image.Size.Width; double heightRatio = newSize.Height / image.Size.Height; double aspectRatio = Math.Min(widthRatio, heightRatio); return(image.Scale(new CGSize(image.Size.Width * aspectRatio, image.Size.Height * aspectRatio))); }
private UIImage CreateScaledImage(UIImage image) { var width = TensorflowLiteService.ModelInputSize; var height = TensorflowLiteService.ModelInputSize; var scaledImage = image.Scale(new CGSize(width, height)); return(scaledImage); }
public void PopulateCell(UIImage image, string text) { UIImage smallImage = image.Scale(new CGSize(this.Frame.Size.Height, this.Frame.Size.Height)); this.ImageView.Image = smallImage; nfloat n = this.ImageView.Frame.Height; SetUpimageAppearance(); this.TextLabel.Text = text; }
private static UIImage ScaleImageInRatio(UIImage image, nfloat reqWidth, nfloat reqHeight) { var width = image.Size.Width; var height = image.Size.Height; CustomImageRenderer.GetRatio(width, height, ref reqWidth, ref reqHeight); image = image.Scale(new CGSize(reqWidth, reqHeight)); return(image); }
public ImageElement (UIImage image) : base ("") { if (image == null){ Value = MakeEmpty (); scaled = Value; } else { Value = image; scaled = Value.Scale(new SizeF(dimx, dimy)); } }
private List <Prediction> Classify(MLModel model, UIImage source) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (source == null) { throw new ArgumentNullException(nameof(source)); } var scaled = source.Scale(new CGSize(227, 227)); var pixelBuffer = ToCVPixelBuffer(scaled); var imageValue = MLFeatureValue.Create(pixelBuffer); var inputs = new NSDictionary <NSString, NSObject>(new NSString("data"), imageValue); NSError error, error2; var inputFp = new MLDictionaryFeatureProvider(inputs, out error); if (error != null) { System.Diagnostics.Debug.WriteLine(error); throw new InvalidOperationException(error.Description); } var outFeatures = model.GetPrediction(inputFp, out error2); if (error2 != null) { System.Diagnostics.Debug.WriteLine(error2); throw new InvalidOperationException(error2.Description); } var predictionsDictionary = outFeatures.GetFeatureValue("loss").DictionaryValue; var byProbability = new List <Tuple <double, string> >(); foreach (var key in predictionsDictionary.Keys) { var description = (string)(NSString)key; var prob = (double)predictionsDictionary[key]; byProbability.Add(new Tuple <double, string>(prob, description)); } byProbability.Sort((t1, t2) => t1.Item1.CompareTo(t2.Item1) * -1); var result = byProbability .Select(p => new Prediction { Label = p.Item2, Probability = p.Item1 }) .ToList(); return(result); }
public async void DownloadAsync(string WineBarcode, int storeid, UIImageView btlImage, nfloat boxHeight) { WebClient webClient = new WebClient(); string url = null; if (storeid == 1) { url = "https://icsintegration.blob.core.windows.net/bottleimagedetailswall/" + WineBarcode + ".jpg"; } else if (storeid == 2) { url = "https://icsintegration.blob.core.windows.net/bottleimagedetailspp/" + WineBarcode + ".jpg"; } byte[] imageBytes = null; try { imageBytes = await webClient.DownloadDataTaskAsync(url); HighImgData = NSData.FromStream(new MemoryStream(imageBytes)); } catch (TaskCanceledException) { //this.progressLayout.Visibility = ViewStates.Gone; return; } catch (Exception exe) { LoggingClass.LogError("while downloading image of wine id" + WineBarcode + " " + exe.Message, screenid, exe.StackTrace.ToString()); } //HighresImg =UIImage.LoadFromData(HighImgData); try { if (HighImgData != null) { UIImage image = UIImage.LoadFromData(HighImgData); nfloat imgHeight = image.Size.Height; nfloat ratio = boxHeight / imgHeight; CGSize newSize = new CGSize(image.Size.Width * ratio, image.Size.Height * ratio); image = image.Scale(newSize); nfloat X = (boxHeight - image.Size.Width) / 2; btlImage.Frame = new CGRect(X, 0, image.Size.Width, image.Size.Height); btlImage.Image = image; } else { btlImage.Image = new UIImage("Wines/bottle.jpg"); } } catch (Exception Ex) { LoggingClass.LogError(Ex.Message, screenid, Ex.StackTrace.ToString()); } }
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); if (Control == null) { return; } if (e.PropertyName == Image.IsLoadingProperty.PropertyName && !this.Element.IsLoading && this.Control.Image != null) { //Should only be true right after an image is loaded int height = 0; int width = 0; int top = 0; int left = 0; switch (this.Element.Aspect) { case Aspect.AspectFill: height = (int)this.Control.Image.Size.Height; width = (int)this.Control.Image.Size.Width; height = this.MakeSquare(height, ref width); left = (((int)this.Control.Image.Size.Width - width) / 2); top = (((int)this.Control.Image.Size.Height - height) / 2); break; case Aspect.Fill: height = (int)this.Control.Image.Size.Height; width = (int)this.Control.Image.Size.Width; break; case Aspect.AspectFit: height = (int)this.Control.Image.Size.Height; width = (int)this.Control.Image.Size.Width; height = this.MakeSquare(height, ref width); left = (((int)this.Control.Image.Size.Width - width) / 2); top = (((int)this.Control.Image.Size.Height - height) / 2); break; } UIImage image = this.Control.Image; var clipRect = new RectangleF(0, 0, width, height); var scaled = image.Scale(new SizeF(width, height)); UIGraphics.BeginImageContextWithOptions(new SizeF(width, height), false, 0f); UIBezierPath.FromRoundedRect(clipRect, Math.Max(width, height) / 2).AddClip(); scaled.Draw(new RectangleF(0, 0, scaled.Size.Width, scaled.Size.Height)); UIImage final = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); this.Control.Image = final; } }
public static UIImage ReescalImage(UIImage ImagenOrigen) { const float MaximunWithHeigth = 646; var withImage = ImagenOrigen.Size.Width; var heightImage = ImagenOrigen.Size.Height; if (withImage > MaximunWithHeigth) { var newHeigth = (heightImage * MaximunWithHeigth) / withImage; CGSize newSizeImage = new CGSize(MaximunWithHeigth, newHeigth); ImagenOrigen = ImagenOrigen.Scale(newSizeImage); } else if (heightImage > MaximunWithHeigth) { var newWith = (MaximunWithHeigth * withImage) / heightImage; CGSize newSizeImage = new CGSize(newWith, MaximunWithHeigth); ImagenOrigen = ImagenOrigen.Scale(newSizeImage); } return(ImagenOrigen); }
/// <summary> /// Loads an image from a bundle given the supplied image name, resizes it to the /// height and width request and sets it into a <see cref="UIButton"/>. /// </summary> /// <param name="source">The <see cref="ImageSource"/> to load the image from.</param> /// <param name="widthRequest">The requested image width.</param> /// <param name="heightRequest">The requested image height.</param> /// <param name="targetButton">A <see cref="UIButton"/> to set the image into.</param> /// <returns>A <see cref="Task"/> for the awaited operation.</returns> private async static Task SetImageAsync(ImageSource source, int widthRequest, int heightRequest, UIButton targetButton) { var handler = GetHandler(source); using (UIImage image = await handler.LoadImageAsync(source)) { targetButton.SetImage( image.Scale(new SizeF(widthRequest, heightRequest)).ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal) , UIControlState.Normal); } }
public override void ViewDidLoad() { base.ViewDidLoad(); datelable.Text = DateTime.Now.Date.ToString(); lblcost.Placeholder = "Must Be Digit"; UIImage img = UIImage.FromFile("BackGround.png"); img = img.Scale(View.Frame.Size); this.View.BackgroundColor = UIColor.FromPatternImage(img); }
public byte[] GetResizedImageBytes(byte[] input, float desireWidth, float desireHeight) { UIImage image = new UIImage(NSData.FromArray(input)); nint scaleFactor = (nint)(image.Size.Width / desireWidth); nint resizeWidth = (nint)(image.Size.Width / scaleFactor); nint resizeHeight = (nint)(image.Size.Height / scaleFactor); var scaledImage = image.Scale(new CGSize(resizeWidth, resizeHeight)); return(scaledImage.AsJPEG().ToArray()); }
public override void ViewDidLoad() { base.ViewDidLoad(); UIGraphics.BeginImageContext(this.View.Frame.Size); UIImage i = UIImage.FromFile(@"BackgroundImages/bg3.jpg"); i = i.Scale(this.View.Frame.Size); this.View.BackgroundColor = UIColor.FromPatternImage(i); ProfileButton.SetTitle(String.Format("{0}", UserDataManager.getDisplayName()), UIControlState.Normal); NavigationItem.SetHidesBackButton(true, false); }
public static UIImage ReescalProfileBackImage(UIImage ImagenOrigen) { const float MaximunWidth = 1500; const float Maximunheight = 500; var withImage = ImagenOrigen.Size.Width; var heightImage = ImagenOrigen.Size.Height; if (withImage > MaximunWidth) { var newHeigth = (heightImage * MaximunWidth) / withImage; CGSize newSizeImage = new CGSize(MaximunWidth, newHeigth); ImagenOrigen = ImagenOrigen.Scale(newSizeImage); } if (heightImage > Maximunheight) { var newWith = (Maximunheight * withImage) / heightImage; CGSize newSizeImage = new CGSize(newWith, Maximunheight); ImagenOrigen = ImagenOrigen.Scale(newSizeImage); } return(ImagenOrigen); }
public static UIImage ReescalProfileImage(UIImage ImagenOrigen) { var withImage = ImagenOrigen.Size.Width; var heightImage = ImagenOrigen.Size.Height; if (withImage > 400 || heightImage > 400) { CGSize newSizeImage = new CGSize(400, 400); ImagenOrigen = ImagenOrigen.Scale(newSizeImage); } return(ImagenOrigen); }
public async Task <bool> CompressImage(Stream fileStream, string inputFile, string outputFile) { NSError error = await Task.Run(() => { Debug.WriteLine($"Original image file '{inputFile}' (Size: {new FileInfo(inputFile).Length / 1024} KB)"); UIImage img = new UIImage(NSData.FromStream(fileStream)); CGSize imgSize = img.Size; switch (ImageCompression.DeterminePrimaryScaleDimension(imgSize.Height, imgSize.Width)) { case ImageCompression.ScaleDown.Height: imgSize = new CGSize( ImageCompression.SecondaryTargetSize(imgSize.Height, imgSize.Width), ImageCompression.MaximumDimension ); img = img.Scale(imgSize); break; case ImageCompression.ScaleDown.Width: imgSize = new CGSize( ImageCompression.MaximumDimension, ImageCompression.SecondaryTargetSize(imgSize.Width, imgSize.Height) ); img = img.Scale(imgSize); break; case ImageCompression.ScaleDown.None: break; } NSData imgData = img.AsJPEG(ImageCompression.CompressionFactorJpegFloat); imgData.Save(outputFile, NSDataWritingOptions.FileProtectionCompleteUntilFirstUserAuthentication, out error); Debug.WriteLine($"Wrote compressed image file to '{outputFile}' (Size: {new FileInfo(outputFile).Length / 1024} KB)"); return(error); }); // TODO: maybe use configure context here return(error == null); }
public static UIImage ResizeImage (SizeF size, UIImage image, bool KeepRatio) { var curSize = image.Size; SizeF newSize; if (KeepRatio) { var ratio = Math.Min (size.Width / curSize.Width, size.Height / curSize.Height); newSize = new SizeF (curSize.Width * ratio, curSize.Height * ratio); } else { newSize = size; } return image.Scale (newSize); }
public void LoadImage(UIImage image) { image = image.Scale(GetScaledSize(image.Size)); scrollView.ZoomScale = 1.0f; profilePicture = image; float zoomScale = CropHelpers.GetZoomScale(profilePicture.Size, scrollView.Frame.Size); var frame = new RectangleF(0f, 0f, image.Size.Width * zoomScale, image.Size.Height * zoomScale); var size = scrollView.Frame.Size; profilePictureView.Frame = frame; profilePictureView.Image = image; scrollView.ContentSize = frame.Size; scrollView.ContentInset = new UIEdgeInsets(size.Height * 0.8f, size.Width * 0.8f, size.Height * 0.8f, size.Width * 0.8f); scrollView.ContentOffset = new PointF(0, 0); }
UIImage Scale (UIImage source) { return source.Scale(new SizeF (dimx, dimy)); }
private void ShowImage(UIImage image, UIImagePickerController picker) { if (this.HasHighResScreen()) image = image.Scale(new SizeF(new PointF(640, 640))); _controller.imageView.Image = image; picker.DismissModalViewControllerAnimated(true); }
private void MySavePicture(UIImage image) { image = image.Scale (image.Size); string[] output = SaveImage (RandomGeneratedName (), image); RaiseSavedImageEvent (output [0], output [1]); }
public static string[] SaveGalleryImage(string name, UIImage ourpic) { if (ourpic == null) return new string[2]{ "", "" }; Console.WriteLine ("Save"); float aspectRatio = ourpic.Size.Width / ourpic.Size.Height; Console.WriteLine ("ratio:" + aspectRatio); float sc = 200; if (!UserInterfaceIdiomIsPhone) { sc = 450; } SizeF newSize = new SizeF (sc, sc / aspectRatio); UIImage thumbPic = ourpic.Scale (newSize); //measurements taken from CustomCell, alternatly 33x33 UIImage resImage = ourpic.Scale (new SizeF (ourpic.Size.Width, ourpic.Size.Height)); if (ourpic != null) { var documentsDirectory = Environment.GetFolderPath (Environment.SpecialFolder.Personal); var gallerydirectory = Path.Combine (documentsDirectory, "gallery"); if (!Directory.Exists (gallerydirectory)) { Directory.CreateDirectory (gallerydirectory); } var picname = name + ".png"; var thumbpicname = name + "_thumb.png"; string pngfileName = System.IO.Path.Combine (gallerydirectory, picname); string thumbpngfileName = System.IO.Path.Combine (gallerydirectory, thumbpicname); NSData imgData = resImage.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]{ "", "" }; }
public static UIImage ResizedImageIcon(UIImage image) { SizeF size = new SizeF (25.0f, 25.0f); UIImage newImage = image.Scale (size, 2.0f); return newImage; }
public static string[] SaveCutout(string name, UIImage ourpic) { if(ourpic == null) return new string[2]{"",""}; Console.WriteLine ("Save"); SizeF newSize = new SizeF (50, 50); UIImage thumbPic = ourpic.Scale (newSize); //measurements taken from CustomCell, alternatly 33x33 UIImage resImage = ourpic.Scale (new SizeF (ourpic.Size.Width, ourpic.Size.Height)); 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 = resImage.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]{"",""}; }
void Picked (UIImage image) { Value = image; scaled = image.Scale(new SizeF(dimx, dimy)); //scaled = GraphicsUtil.PrepareForProfileView(image, dimx, dimy); currentController.DismissModalViewControllerAnimated (true); }