Example #1
0
 /// <summary>
 /// Gets or sets image channel.
 /// Channel size must be the same as image size.
 /// </summary>
 /// <param name="channelIdx">Index of an channel to get or replace.</param>
 /// <returns>Image channel.</returns>
 IImage IImage.this[int channelIdx]
 {
     get
     {
         return(ChannelSplitter.SplitChannels(this, channelIdx)[0]);
     }
     set
     {
         ChannelMerger.MergeChannels(new IImage[] { value }, this, channelIdx);
     }
 }
        private unsafe static Array toArray(IImage image)
        {
            Array arr = Array.CreateInstance(image.ColorInfo.ChannelType, image.ColorInfo.NumberOfChannels, image.Height, image.Width);

            var channelColor = ColorInfo.GetInfo(typeof(Gray), image.ColorInfo.ChannelType);

            GCHandle arrHandle    = GCHandle.Alloc(arr, GCHandleType.Pinned);
            int      arrDimStride = image.Width * channelColor.Size;

            IImage[] channels = (image.ColorInfo.NumberOfChannels == 1) ? new IImage[] { image } : ChannelSplitter.SplitChannels(image);

            for (int i = 0; i < channels.Length; i++)
            {
                int    dimOffset = i * arrDimStride * image.Height;
                IntPtr dimPtr    = (IntPtr)((byte *)arrHandle.AddrOfPinnedObject() + dimOffset);

                var channelImg = channels[i];
                HelperMethods.CopyImage(channelImg.ImageData, dimPtr, channelImg.Stride, arrDimStride, arrDimStride, image.Height);
            }

            arrHandle.Free();

            return(arr);
        }