예제 #1
0
 /* ----------------------------------------------------------------- */
 ///
 /// ImageConverter
 ///
 /// <summary>
 /// オブジェクトを初期化します。
 /// </summary>
 ///
 /// <param name="format">変換後のフォーマット</param>
 /// <param name="io">I/O オブジェクト</param>
 ///
 /* ----------------------------------------------------------------- */
 public ImageConverter(Format format, IO io) : base(format, io)
 {
     if (!SupportedFormats.Contains(format))
     {
         throw new NotSupportedException();
     }
 }
예제 #2
0
        /// <summary>
        /// Process image looking for corners.
        /// </summary>
        ///
        /// <param name="image">Source image to process.</param>
        ///
        /// <returns>Returns list of found corners (X-Y coordinates).</returns>
        ///
        /// <exception cref="UnsupportedImageFormatException">The source image has incorrect pixel format.</exception>
        ///
        public new List <IntPoint> ProcessImage(Bitmap image)
        {
            // check image format
            if (!SupportedFormats.Contains(image.PixelFormat))
            {
                throw new UnsupportedImageFormatException("Unsupported pixel format of the source image.");
            }

            // lock source image
            BitmapData imageData = image.LockBits(ImageLockMode.ReadOnly);

            List <IntPoint> corners;

            try
            {
                // process the image
                corners = ProcessImage(new UnmanagedImage(imageData));
            }
            finally
            {
                // unlock image
                image.UnlockBits(imageData);
            }

            return(corners);
        }
        /// <summary>
        ///   Applies the transformation to an input, producing an associated output.
        /// </summary>
        ///
        /// <param name="input">The input data to which the transformation should be applied.</param>
        ///
        /// <returns>The output generated by applying this transformation to the given input.</returns>
        ///
        public IEnumerable <TFeature> Transform(Signal input)
        {
            // check image format
            if (!SupportedFormats.Contains(input.SampleFormat))
            {
                throw new UnsupportedSampleFormatException("Unsupported pixel format of the source image.");
            }

            return(InnerTransform(input));
        }
예제 #4
0
        /// <summary>
        /// Process image looking for corners.
        /// </summary>
        ///
        /// <param name="input">Source image data to process.</param>
        ///
        /// <returns>Returns list of found corners (X-Y coordinates).</returns>
        ///
        /// <exception cref="UnsupportedImageFormatException">The source image has incorrect pixel format.</exception>
        ///
        public new List <IntPoint> ProcessImage(UnmanagedImage input)
        {
            // check image format
            if (!SupportedFormats.Contains(input.PixelFormat))
            {
                throw new UnsupportedImageFormatException("Unsupported pixel format of the source image.");
            }

            return(InnerProcess(input));
        }
예제 #5
0
        public DiscordImage Download(DiscordCDNImageFormat format = DiscordCDNImageFormat.Any)
        {
            if (format != DiscordCDNImageFormat.Any && SupportedFormats != null && !SupportedFormats.Contains(format))
            {
                throw new NotSupportedException("Image format not supported. Supported formats for this endpoint: " + string.Join(", ", SupportedFormats));
            }

            string extension = format == DiscordCDNImageFormat.Any ? "" : $".{format.ToString().ToLower()}";

            try
            {
                return(new DiscordImage((Bitmap) new ImageConverter().ConvertFrom(new HttpClient().GetByteArrayAsync(Url + extension).Result)));
            }
            catch
            {
                return(null);
            }
        }
        public bool CheckImage(FilePath path)
        {
            int    width, height;
            string errorTitle   = null;
            string errorMessage = null;

            using (var type = Pixbuf.GetFileInfo(path, out width, out height))
            {
                if (type == null)
                {
                    errorTitle   = GettextCatalog.GetString("Invalid file selected");
                    errorMessage = GettextCatalog.GetString("Selected file was not a valid image.");
                }
                else if (type.IsDisabled)
                {
                    errorTitle   = GettextCatalog.GetString("Unsupported image selected");
                    errorMessage = GettextCatalog.GetString("Support for loading images of type '{0}' has not been enabled.", type.Name);
                }
                else if (AcceptedSize != Size.Empty && AcceptedSize != new Size(width, height))
                {
                    errorTitle   = GettextCatalog.GetString("Incorrect image dimensions");
                    errorMessage = GettextCatalog.GetString(
                        "Only images with size {0}x{1} are allowed. Picture was {2}x{3}.",
                        AcceptedSize.Width, AcceptedSize.Height, width, height);
                }
                else if (!SupportedFormats.Contains(type.Name))
                {
                    var formats = string.Join(", ", SupportedFormats.Select(f => "'" + f + "'"));
                    errorTitle   = GettextCatalog.GetString("Invalid image selected");
                    errorMessage = GettextCatalog.GetString("An image of type '{0}' has been selected but you must select an image of type '{1}'.", type.Name, formats);
                }
                else
                {
                    return(true);
                }

                LoggingService.LogError("{0}: {1}", errorTitle, errorMessage);
                MessageService.ShowError(errorTitle, errorMessage);
                return(false);
            }
        }