static CoreGraphics.CGImage[] GetFrames(CGImageSource source, CGImageThumbnailOptions options) { var retval = new CoreGraphics.CGImage[source.ImageCount]; for (int i = 0; i < source.ImageCount; i++) { var frameImage = source.CreateThumbnail(i, options); retval[i] = frameImage; } return(retval); }
protected override UIImage Transform(UIImage sourceBitmap, string path, ImageSource source, bool isPlaceholder, string key) { var effect = new CIPhotoEffectMono() { InputImage = sourceBitmap.CGImage }; var output = effect.OutputImage; var context = CIContext.FromOptions(null); CoreGraphics.CGImage cgimage = context.CreateCGImage(output, output.Extent); return(UIImage.FromImage(cgimage)); }
public void TakeScreenshot(string screenshotPath) { #if MAC DispatchService.GuiDispatch(delegate { try { IntPtr handle = CGDisplayCreateImage(MainDisplayID()); CoreGraphics.CGImage screenshot = ObjCRuntime.Runtime.GetINativeObject <CoreGraphics.CGImage> (handle, true); AppKit.NSBitmapImageRep imgRep = new AppKit.NSBitmapImageRep(screenshot); var imageData = imgRep.RepresentationUsingTypeProperties(AppKit.NSBitmapImageFileType.Png); imageData.Save(screenshotPath, true); } catch (Exception e) { Console.WriteLine(e); throw; } }); #endif }
public void TakeScreenshot(string screenshotPath) { #if MAC Runtime.RunInMainThread(delegate { try { IntPtr handle = CGDisplayCreateImage(MainDisplayID()); CoreGraphics.CGImage screenshot = ObjCRuntime.Runtime.GetINativeObject <CoreGraphics.CGImage> (handle, true); AppKit.NSBitmapImageRep imgRep = new AppKit.NSBitmapImageRep(screenshot); var imageData = imgRep.RepresentationUsingTypeProperties(AppKit.NSBitmapImageFileType.Png); imageData.Save(screenshotPath, true); } catch (Exception e) { Console.WriteLine(e); throw; } }); #else Sync(delegate { try { using (var bmp = new System.Drawing.Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height)) { using (var g = System.Drawing.Graphics.FromImage(bmp)) { g.CopyFromScreen(System.Windows.Forms.Screen.PrimaryScreen.Bounds.X, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Y, 0, 0, bmp.Size, System.Drawing.CopyPixelOperation.SourceCopy); } bmp.Save(screenshotPath); } return(null); } catch (Exception e) { Console.WriteLine(e); throw; } }); #endif }
public static void TestCapture() { Foundation.NSNumber mainScreen = (Foundation.NSNumber)AppKit.NSScreen.MainScreen.DeviceDescription["NSScreenNumber"]; using (CoreGraphics.CGImage cgImage = CreateImage(mainScreen.UInt32Value)) { // https://stackoverflow.com/questions/17334786/get-pixel-from-the-screen-screenshot-in-max-osx/17343305#17343305 // Get byte-array from CGImage // https://gist.github.com/zhangao0086/5fafb1e1c0b5d629eb76 AppKit.NSBitmapImageRep bitmapRep = new AppKit.NSBitmapImageRep(cgImage); // var imageData = bitmapRep.representationUsingType(NSBitmapImageFileType.NSPNGFileType, properties: [:]) Foundation.NSData imageData = bitmapRep.RepresentationUsingTypeProperties(AppKit.NSBitmapImageFileType.Png); long len = imageData.Length; byte[] bytes = new byte[len]; System.Runtime.InteropServices.GCHandle pinnedArray = System.Runtime.InteropServices.GCHandle.Alloc(bytes, System.Runtime.InteropServices.GCHandleType.Pinned); System.IntPtr pointer = pinnedArray.AddrOfPinnedObject(); // Do your stuff... imageData.GetBytes(pointer, new System.IntPtr(len)); pinnedArray.Free(); using (AppKit.NSImage nsImage = new AppKit.NSImage(cgImage, new System.Drawing.SizeF(cgImage.Width, cgImage.Height))) { // ImageView.Image = nsImage; // And now ? How to get the image bytes ? // https://theconfuzedsourcecode.wordpress.com/2016/02/24/convert-android-bitmap-image-and-ios-uiimage-to-byte-array-in-xamarin/ // https://stackoverflow.com/questions/5645157/nsimage-from-byte-array // https://stackoverflow.com/questions/53060723/nsimage-source-from-byte-array-cocoa-app-xamarin-c-sharp // https://gist.github.com/zhangao0086/5fafb1e1c0b5d629eb76 // https://www.quora.com/What-is-a-way-to-convert-UIImage-to-a-byte-array-in-Swift?share=1 // https://stackoverflow.com/questions/17112314/converting-uiimage-to-byte-array } // End Using nsImage } // End Using cgImage } // End Sub TestCapture
public void print(SKBitmap toPrint) { try { BRPtouchPrintInfo printInfo = new BRPtouchPrintInfo(); printInfo.StrPaperName = @"36mm"; printInfo.NPrintMode = (int)PrintFlags.PRINT_FIT; printInfo.NOrientation = (int)PrintFlags.ORI_LANDSCAPE; printInfo.NHorizontalAlign = (int)PrintFlags.ALIGN_CENTER; printInfo.NVerticalAlign = (int)PrintFlags.ALIGN_MIDDLE; printInfo.BHalfCut = true; printInfo.BEndcut = true; printInfo.NAutoCutFlag = (int)PrintFlags.OPTION_AUTOCUT; printInfo.NAutoCutCopies = 1; printInfo.NCustomLength = toPrint.Width; BRPtouchPrinter printer = new BRPtouchPrinter("Brother PT-P950NW", ConnectionType.Wlan); printer.SetIPAddress("192.168.43.126"); //192.168.43.126 printer.SetPrintInfo(printInfo); bool worked = printer.StartCommunication(); if (worked) { using (CoreGraphics.CGImage cgImage2 = new CoreGraphics.CGImage(toPrint.Width, toPrint.Height, 8, toPrint.BytesPerPixel * 8, toPrint.BytesPerPixel * toPrint.Width, CoreGraphics.CGColorSpace.CreateGenericGray(), CoreGraphics.CGBitmapFlags.None, new CoreGraphics.CGDataProvider(toPrint.Bytes), null, false, CoreGraphics.CGColorRenderingIntent.Default)) { BRPtouchPrinterErrors result2 = (BRPtouchPrinterErrors)printer.PrintImage(cgImage2, 1); printer.EndCommunication(); } } } catch (Exception ex) { System.Console.WriteLine("ERROR: " + ex.Message + "\r\n" + ex.StackTrace); } }
partial void Init(CoreGraphics.CGImage img);
public Image(CoreGraphics.CGImage img) { Init(img); }
public NSBitmapImageRep(CoreGraphics.CGImage cgImage) { }
private void bw_SaveMulti(object sender, System.ComponentModel.DoWorkEventArgs e) { List <ALAsset> results = (List <ALAsset>)e.Argument; List <string> errors = new List <string> (); using (Connection sqlConn = new Connection(SQLiteBoostDB.GetDBPath())) { VehicleImagesDB vidb = new VehicleImagesDB(sqlConn); vidb.RemoveAllImages(this.vehicleId); } var imagePath = Graphics.GetImagePath(vehicleId); int counter = 0; foreach (var asset in results) { var obj = asset.AssetType; if (obj == default(ALAssetType)) { continue; } using (var rep = asset.DefaultRepresentation) { if (rep != null) { //var result = new AssetResult (); using (CoreGraphics.CGImage cgImage = rep.GetFullScreenImage()) { UIImageOrientation orientation = UIImageOrientation.Up; using (UIImage uiImage = new UIImage(cgImage, 1.0f, orientation)) { counter++; string filePath = Path.Combine(imagePath, "image_" + counter + ".jpg"); string thumbPath = Path.Combine(imagePath, "thumb_" + counter + ".jpg"); NSError fileError, thumbError; try { if (!Directory.Exists(imagePath)) { Directory.CreateDirectory(imagePath); } if (File.Exists(filePath)) { File.Delete(filePath); } if (File.Exists(thumbPath)) { File.Delete(thumbPath); } using (NSData jpegData = uiImage.AsJPEG()) { jpegData.Save(filePath, NSDataWritingOptions.Atomic, out fileError); using (UIImage thumb = Graphics.ResizeImage(UIImage.LoadFromData(jpegData), 100f, 75f)) thumb.AsJPEG().Save(thumbPath, NSDataWritingOptions.Atomic, out thumbError); if (fileError != null) { throw new Exception("Error saving image. " + fileError.ToString()); } if (thumbError != null) { throw new Exception("Error saving thumbnail. " + thumbError.ToString()); } Graphics.SaveImage(counter, filePath, vehicleId); } } catch (Exception ex) { errors.Add(ex.ToString()); } } } } } } results = null; e.Result = errors; }
public NSImage(CoreGraphics.CGImage image, System.Drawing.SizeF size) { }