Beispiel #1
0
        public static IplImage ByteArrayToIplImage(byte[] imageBuffer, LoadMode loadMode)
        {
            //  OpenCvSharp.CPlusPlus.Mat m = Cv.EncodeImage(".jpg", img);
            IplImage res = IplImage.FromImageData((byte[])imageBuffer, loadMode);

            if (res == null)
            {
                Bitmap img = null;
                using (var ms = new System.IO.MemoryStream(imageBuffer))
                {
                    img = Image.FromStream(ms) as Bitmap;
                }
                Stream str = VaryQualityLevel(img);
                if (str != null)
                {
                    imageBuffer = ReadStreamToEnd(str);
                    str.Dispose();
                    str = null;
                }
                res = IplImage.FromImageData((byte[])imageBuffer, loadMode);
            }
            return(res);
        }