Esempio n. 1
0
        private USBH_Webcam.ImageFormat GetImageFormat(PictureResolution pictureResolution)
        {
            USBH_Webcam.ImageFormat   imageFormat = null;
            USBH_Webcam.ImageFormat[] imageFormats;

            if (_camera != null)
            {
                try {
                    imageFormats = _camera.GetSupportedFormats();
                    for (int i = 0; i < imageFormats.Length; i++)
                    {
                        if (imageFormats[i].Width == pictureResolution.Width && imageFormats[i].Height == pictureResolution.Height)
                        {
                            imageFormat = imageFormats[i];
                        }
                    }
                }
                catch {
                    throw new Exception("Unable to get supported image formats from camera.");
                }
            }
            else
            {
                throw new Exception("Camera must be connected to be able to get valid image formats.");
            }

            if (imageFormat != null)
            {
                return(imageFormat);
            }
            else
            {
                throw new ArgumentException("No valid image formats were found for the specified PictureResolution.");
            }
        }
Esempio n. 2
0
        private void loadimg()
        {
            PictureResolution pr       = new PictureResolution();
            StringBuilder     temphtml = new StringBuilder();

            //Bitmap bmp= pr.ReadImageFile(@"D:\picdome\1.jpg",out temphtml);

            System.Drawing.Image[] imarray = pr.SplitImage(@"D:\picdome\1.jpg", 640, 400, string.Empty, string.Empty, System.Drawing.Imaging.ImageFormat.Png, false);
            List <string>          img64   = new List <string>();

            foreach (System.Drawing.Image im in imarray)
            {
                //byte[] imgbyte= pr.GetByteImage(im);
                // MemoryStream ms = new MemoryStream();
                // byte[] arr = new byte[imgbyte.Length];
                // ms.Position = 0;
                // ms.Read(arr, 0, (int)imgbyte.Length);
                // ms.Close();
                // string pic = Convert.ToBase64String(arr);
                img64.Add(pr.GetBase64String(im));
            }
            int countemp = 0;

            StringBuilder strBuilder = new StringBuilder();

            strBuilder.Append("{\"width\":" + pr.WidthNumber + ",\"hight\":" + pr.HeightNumber
                              + ",  \"imglist\":[");
            for (int i = 0; i < img64.Count; i++)
            {
                //temphtml.Append("<tr>");
                //for (int j = 0; j < pr.WidthNumber; j++)
                //{
                //temphtml.Append("<td><image src=\"data:image/png;base64," + img64[countemp] + "\"/></td>");
                strBuilder.Append("{\"imgstring\":\"" + img64[i] + "\"},");
                //countemp++;
                //if (countemp >= img64.Count) break;
                //if (countemp >= 100) break;
                //}
                //temphtml.Append("</tr>");
            }
            //rowInnerHtml += temphtml.ToString();

            //foreach (APPLFSEvalProject _m in li)
            //{

            //}
            json = strBuilder.ToString().TrimEnd(',') + "]}";
            //MemoryStream ms = new MemoryStream();
            //bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
            //Response.ContentType = "image/bmp";
            //Response.BinaryWrite(ms.ToArray());
            //rowInnerHtml = temphtml.ToString();
            //Color pixelColor = bmp.GetPixel(50, 50);
            //var s = pixelColor.Name;
        }
Esempio n. 3
0
        private Webcam.ImageFormat GetImageFormat(PictureResolution resolution)
        {
            if (this.camera == null)
            {
                throw new InvalidOperationException("No camera is connected.");
            }

            foreach (var f in this.camera.SupportedFormats)
            {
                if (f.Width == resolution.Width && f.Height == resolution.Height)
                {
                    return(f);
                }
            }

            throw new ArgumentException("The connected camera does not supported the specified resolution.");
        }