示例#1
0
 /// <summary>
 /// Copy the data from the CGImage to the current Image object
 /// </summary>
 internal static void ToImage <TColor, TDepth>(this CGImage cgImage, Image <TColor, TDepth> image)
     where TColor : struct, IColor
     where TDepth : new()
 {
     //Don't do this, Xamarin.iOS won't be able to resolve: if (this is Image<Rgba, Byte>)
     if (typeof(TColor) == typeof(Rgba) && typeof(TDepth) == typeof(byte))
     {
         Debug.Assert((image.Width == (int)cgImage.Width) && (image.Height == (int)cgImage.Height), "Incompatible dimension between the CGImage and Image<,>.");
         RectangleF rect = new RectangleF(PointF.Empty, new SizeF(cgImage.Width, cgImage.Height));
         using (CGColorSpace cspace = CGColorSpace.CreateDeviceRGB())
             using (CGBitmapContext context = new CGBitmapContext(
                        image.MIplImage.ImageData,
                        image.Width, image.Height,
                        8,
                        image.Width * 4,
                        cspace,
                        CGImageAlphaInfo.PremultipliedLast))
                 context.DrawImage(rect, cgImage);
     }
     else
     {
         using (Image <Rgba, Byte> tmp = cgImage.ToImage <Rgba, Byte>())
             image.ConvertFrom(tmp);
     }
 }
示例#2
0
 /// <summary>
 /// Creating an Image from the UIImage
 /// </summary>
 public static Image <TColor, TDepth> ToImage <TColor, TDepth> (this UIImage uiImage)
     where TColor : struct, IColor
     where TDepth : new()
 //: this( (int) uiImage.Size.Width, (int) uiImage.Size.Height)
 {
     using (CGImage cgImage = uiImage.CGImage) {
         return(cgImage.ToImage <TColor, TDepth> ());
     }
 }
示例#3
0
        /// <summary>
        /// Creating an Image from the CGImage
        /// </summary>
        public static Image <TColor, TDepth> ToImage <TColor, TDepth>(this CGImage cgImage)
            where TColor : struct, IColor
            where TDepth : new()

        {
            Image <TColor, TDepth> image = new Image <TColor, TDepth>((int)cgImage.Width, (int)cgImage.Height);

            cgImage.ToImage <TColor, TDepth>(image);
            return(image);
        }