示例#1
0
        /// <summary>
        /// Casts an image to its given image type and returns its base class.
        /// </summary>
        /// <param name="image">The image to cast.</param>
        /// <param name="format">The format to cast.</param>
        /// <returns>The image as <see cref="IMAGE"/> of its proper format.</returns>
        public static IMAGE ProperCast(Image image, ImgFormat format)
        {
            switch (format)
            {
            case ImgFormat.png:
                return(new PNG(image));

            case ImgFormat.bmp:
                return(new BMP(image));

            case ImgFormat.gif:
                return(new Gif(image));

            case ImgFormat.jpg:
                return(new JPEG(image));

            case ImgFormat.tif:
                return(new TIFF(image));

            case ImgFormat.webp:
                return(new Webp(image));

            case ImgFormat.wrm:
                return(new WORM(image));

            case ImgFormat.ico:
                return(new ICO(image));
            }
            return(null);
        }
示例#2
0
        private static TextureFormat GetTextureFormat(ImgFormat imgFormat, string entityToken)
        {
            // Convert STP image format to Unity texture format
            TextureFormat texFormat;

            switch (imgFormat)
            {
            case ImgFormat.RawRGBA:
                texFormat = TextureFormat.RGBA32;
                break;

            case ImgFormat.RawRGB:
                texFormat = TextureFormat.RGB24;
                break;

            case ImgFormat.RawGray:
                texFormat = TextureFormat.R8;
                break;

            default:
                Debug.LogWarningFormat("Unknown texture type for item {0}! Using RGBA32 type.", entityToken);
                texFormat = TextureFormat.RGBA32;
                break;
            }

            return(texFormat);
        }
示例#3
0
 //-----------READING AND CONVERTING IMG TO GREY SCALE-----------------
 private void ReadPic(ImgFormat imf, int width, int height)
 {
     try
     {
         Bitmap b = new Bitmap(this.FileName);
         this.BmpImg = new Bitmap(b, new Size(width, height));
         ImgVector   = new double[width * height];
         int   k = 0;
         int   r1a, g1a, b1a, gray;
         Color c1;
         for (int i = 0; i < height; i++)
         {
             for (int j = 0; j < width; j++)
             {
                 c1  = b.GetPixel(j, i);
                 r1a = c1.R;
                 g1a = c1.G;
                 b1a = c1.B;
                 if (r1a != b1a)
                 {
                     gray = (int)(.299 * r1a + .587 * g1a + .114 * b1a); //CONVERTING PIXELS TO GREY
                 }
                 else
                 {
                     gray = b1a;
                 }
                 ImgVector[k++] = gray;
             }
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message + "ImageArray Creation Error");
     }
 }
        internal void DownloadImagesFromURL(string url, ImgFormat frmt)
        {
            List<string> lst = GetAllImageURLListFromWebPage(url);

            int imgCt = 0;
            foreach (string s in lst)
                imgCt = SaveFileInTempFolder(s, imgCt, frmt);
        }
示例#5
0
        public static void UpdateTexture(TextureData textureData)
        {
            ImgFormat imgFormat = (ImgFormat)textureData.imgFormat;

            Debug.LogFormat("Texture Update - Token:{0}, {1} width {2} height {3} image type", textureData.entityToken, textureData.width, textureData.height, imgFormat);

            Texture2D texture = PackageMapper.GetTexture2DFromToken(textureData.entityToken);

            UpdateTextureData(texture, textureData, imgFormat);
        }
示例#6
0
 /// <summary>
 /// Generates a placeholder image via the http://placehold.it web service
 /// </summary>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="text"></param>
 /// <param name="backgroundColor"></param>
 /// <param name="textColor"></param>
 /// <param name="format"></param>
 /// <returns>Returns an HTML image element with the specified parameters</returns>
 public static MvcHtmlString Placehold(this HtmlHelper html, int width, int height, string text = null, string backgroundColor = null, string textColor = null, object htmlAttributes = null, ImgFormat format = ImgFormat.GIF)
 {
     var placeholder = new TagBuilder("img");
     var options = new StringBuilder();
     placeholder.MergeAttributes(htmlAttributes != null ? HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes) : null);
     options.AppendFormat(format == ImgFormat.GIF ? "" : ".{0}", format);
     options.AppendFormat(backgroundColor != null ? "/{0}" : "", backgroundColor);
     options.AppendFormat(textColor != null ? "/{0}" : "", textColor);
     options.AppendFormat(text != null ? "&text={0}" : "", text);
     placeholder.Attributes.Add("src", string.Format("http://placehold.it/{0}x{1}{2}", width, height, options));
     return MvcHtmlString.Create(placeholder.ToString(TagRenderMode.SelfClosing));
 }
示例#7
0
        public static GenFuConfigurator <T> AsPlaceholderImage <T>(this GenFuStringConfigurator <T> configurator,
                                                                   int width, int height,
                                                                   string text            = null,
                                                                   string backgroundColor = null,
                                                                   string textColor       = null,
                                                                   ImgFormat format       = ImgFormat.GIF) where T : new()
        {
            CustomFiller <string> filler = new CustomFiller <string>(configurator.PropertyInfo.Name, typeof(T),
                                                                     () => PlaceholditUrlBuilder.UrlFor(width, height, text, backgroundColor, textColor, format));

            configurator.Maggie.RegisterFiller(filler);
            return(configurator);
        }
示例#8
0
        public static Object CreateTexture(TextureData textureData)
        {
            ImgFormat     imgFormat = (ImgFormat)textureData.imgFormat;
            TextureFormat texFormat = GetTextureFormat(imgFormat, textureData.entityToken);

            Debug.LogFormat("Texture - Token:{0}, {1} width {2} height {3} image type", textureData.entityToken, textureData.width, textureData.height, imgFormat);

            // Create a new Unity texture
            Texture2D newTexture = new Texture2D(textureData.width, textureData.height, texFormat, true);

            UpdateTextureData(newTexture, textureData, imgFormat);

            // Create texture folders if they don't exist
            PackageMapper.CreateAssetFolders(TextureHandler.assetPath);

            // Generate a unique texture name
            string texturePath = Application.dataPath + "/" + TextureHandler.assetPath;
            string uniqueTextureName;

            GenUniqueTextureAssetName(texturePath, textureData.displayName, out uniqueTextureName);

            // Set the unique texture name as the display name
            newTexture.name = uniqueTextureName;

            // Create a GameObject prefab object and use it as a database item of STP used textures
            GameObject texturePrefab = new GameObject(textureData.displayName);

            // Add Foundry unique token storage component, store unique texture token
            var tokenStorage = texturePrefab.AddComponent <FoundryUniqueToken>();

            tokenStorage.uniqueToken = textureData.entityToken;

            // Create the prefab asset
            var    localPrefabPath = System.String.Format("{0}/{1}/{2}", PackageMapper.rootPath, TextureHandler.assetPath, uniqueTextureName);
            string prefabPath;

            PackageMapper.GenUniquePrefabAssetPath(localPrefabPath, out prefabPath);

#if UNITY_2018_3_OR_NEWER
            Object prefabAsset = PrefabUtility.SaveAsPrefabAsset(texturePrefab, prefabPath);
#else
            Object prefabAsset = PrefabUtility.CreatePrefab(prefabPath, texturePrefab);
#endif
            AssetDatabase.AddObjectToAsset(newTexture, prefabAsset);
            AssetDatabase.SaveAssets();

            // Remove game object that's used for creating a prefab from scene hierarchy
            Object.DestroyImmediate(texturePrefab);

            return(prefabAsset);
        }
        private int DownloadFileTypesFromURL(string url, int imgCt, ImgFormat frmt)
        {
            string[] spltURL = url.Split('.');
            if (spltURL[spltURL.Length - 1] == frmt.ToString())
            {
                if (wc == null)
                    wc = new WebClient();

                wc.DownloadFile(url, tmpFileLocation + imgCt.ToString() + "." + frmt);
                return ++imgCt;
            }
            else
                return imgCt;
        }
示例#10
0
        public MyImage(string fname, string id, int width, int height, ImgFormat imf, ImgComparison imc)
        {
            FileInfo finfo   = new FileInfo(fname);
            string   dirName = finfo.Directory.Name;

            this.FileNameShort = finfo.Name;
            this.Id            = id;
            this.FileName      = fname;
            imgCompareMode     = imc;
            ReadPic(imf, width, height); // read the picture into an 1-D array
            FindImageMean();
            this.ImgVectorAdjM = new double[width * height];
            this.FSV           = new double[width * height];
        }
示例#11
0
 public static string UrlFor(
     int width,
     int height,
     string text            = null,
     string backgroundColor = null,
     string textColor       = null,
     ImgFormat format       = ImgFormat.GIF) =>
 new StringBuilder()
 .Append("http://placehold.it/")
 .Append($"{width}x{height}")
 .AppendWhen($".{format}", format != ImgFormat.GIF)
 .AppendWhen($"/{backgroundColor}", !string.IsNullOrWhiteSpace(backgroundColor))
 .AppendWhen($"/{textColor}", !string.IsNullOrWhiteSpace(textColor))
 .AppendWhen($"?text={text}", !string.IsNullOrWhiteSpace(text))
 .ToString();
示例#12
0
        private void SaveImg_btn_Click(object sender, EventArgs e)
        {
            using (var SaveFile = new SaveFileDialog())
            {
                if (Functional_Tab.SelectedTab == Convert_Img_Page)
                {
                    var Extension_selected = ImgExtension.SelectedItem;
                    SaveFile.Filter = $"Image Files(*.{Extension_selected})|*.{Extension_selected.ToString().ToLower()}|All Files(*.*)|*.*";

                    if (SaveFile.ShowDialog() == DialogResult.OK)
                    {
                        try
                        {
                            switch (Extension_selected)
                            {
                            case "PNG":
                                ImgFormat.ToPng(image_directory, SaveFile.FileName);
                                break;

                            case "ICO":
                                break;

                            case "JPG":
                                ImgFormat.ToJpg(image_directory, SaveFile.FileName);
                                break;

                            case "BMP":
                                ImgFormat.ToBmp(image_directory, SaveFile.FileName);
                                break;

                            case "TIFF":
                                ImgFormat.ToTiff(image_directory, SaveFile.FileName);
                                break;
                            }
                            MessageBox.Show("Изображение успешно сконвертировано", "Успех!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        catch
                        {
                            MessageBox.Show("Не удалось сохранить изображение", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                else if (Functional_Tab.SelectedTab == Edit_Img_Page)
                {
                    Compress_Image.Compress(image_directory, Compression_ratio_bar.Value);
                }
            }
        }
示例#13
0
        public static WireframeGenerator Image(this WireframeGenerator gen,
                                               int width,
                                               int height,
                                               string text            = null,
                                               string backgroundColor = null,
                                               string textColor       = null,
                                               object htmlAttributes  = null,
                                               ImgFormat format       = ImgFormat.GIF)
        {
            var img = new TagBuilder("img");

            img.TagRenderMode = TagRenderMode.SelfClosing;
            img.Attributes.Add("src", PlaceholditUrlBuilder.UrlFor(width, height, text, backgroundColor, textColor));
            img.MergeAttributes(HtmlAttributeHelper.GetHtmlAttributeDictionaryOrNull(htmlAttributes));
            return(gen.Add(img));
        }
示例#14
0
        /// <summary>
        /// 转换成Net内置的ImageFormat
        /// </summary>
        /// <param name="format"></param>
        /// <param name="defaultImageFormat">转换成系统支持的图片格式</param>
        /// <returns></returns>
        public static ImageFormat GetImageFormat(this ImgFormat format, ImageFormat defaultImageFormat)
        {
            var imageFormat = defaultImageFormat;

            switch (format)
            {
            case ImgFormat.Bmp:
            {
                imageFormat = ImageFormat.Bmp;
                break;
            }

            case ImgFormat.Gif:
            {
                imageFormat = ImageFormat.Gif;
                break;
            }

            case ImgFormat.Jpg:
            {
                imageFormat = ImageFormat.Jpeg;
                break;
            }

            case ImgFormat.Png:
            {
                imageFormat = ImageFormat.Png;
                break;
            }

            case ImgFormat.Tiff:
            {
                imageFormat = ImageFormat.Tiff;
                break;
            }

            case ImgFormat.Ico:
            {
                imageFormat = ImageFormat.Icon;
                break;
            }
            }

            return(imageFormat);
        }
示例#15
0
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <returns></returns>
        public ActionResult UploadImage()
        {
            HttpFileCollectionBase files = Request.Files;
            // bool isWideImage = Request["Select_ImgShowType"] == "1";
            Dictionary <string, string> result = new Dictionary <string, string>();
            HttpPostedFileBase          image1 = (HttpPostedFileBase)Request.Files["img1"];
            HttpPostedFileBase          image2 = (HttpPostedFileBase)Request.Files["img2"];
            HttpPostedFileBase          image3 = (HttpPostedFileBase)Request.Files["img3"];

            ImgFormat format = null;


            format = new ImgFormat(1, ImgFormatType.Spec, 140, 90);


            if (image1 != null)
            {
                ImgUploadRet imgRet = ImgUtil.UploadImag(image1, format);
                if (imgRet.IsSuc)
                {
                    result["img1"] = imgRet.GetImgUrl(1);
                }
            }
            if (image2 != null)
            {
                ImgUploadRet imgRet = ImgUtil.UploadImag(image2, format);
                if (imgRet.IsSuc)
                {
                    result["img2"] = imgRet.GetImgUrl(1);
                }
            }
            if (image3 != null)
            {
                ImgUploadRet imgRet = ImgUtil.UploadImag(image3, format);
                if (imgRet.IsSuc)
                {
                    result["img3"] = imgRet.GetImgUrl(1);
                }
            }

            return(Json(result));
        }
示例#16
0
        public static GenFuConfigurator <T> AsPlaceholderImage <T>(this GenFuStringConfigurator <T> configurator,
                                                                   int width, int height,
                                                                   string text            = null,
                                                                   string backgroundColor = null,
                                                                   string textColor       = null,
                                                                   object htmlAttributes  = null,
                                                                   ImgFormat format       = ImgFormat.GIF) where T : new()
        {
            CustomFiller <string> filler = new CustomFiller <string>(configurator.PropertyInfo.Name, typeof(T),
                                                                     () => new StringBuilder()
                                                                     .Append("http://placehold.it/")
                                                                     .Append($"{width}x{height}")
                                                                     .AppendWhen($".{format}", format != ImgFormat.GIF)
                                                                     .AppendWhen($"/{backgroundColor}", !string.IsNullOrWhiteSpace(backgroundColor))
                                                                     .AppendWhen($"/{textColor}", !string.IsNullOrWhiteSpace(textColor))
                                                                     .AppendWhen($"?text={text}", !string.IsNullOrWhiteSpace(text))
                                                                     .ToString());

            configurator.Maggie.RegisterFiller(filler);
            return(configurator);
        }
示例#17
0
 public ImagesTransformer(XElement xe, Workflow wf)
     : base(xe, wf)
 {
     OutputFilePattern = GetSetting("outputFilePattern");
     OutputFormat      = (ImgFormat)Enum.Parse(typeof(ImgFormat), GetSetting("outputFormat"), true);
 }
示例#18
0
        public static IMAGE LoadImage(string path, bool showError = false)
        {
            if (string.IsNullOrEmpty(path) || !File.Exists(path))
            {
                return(null);
            }

            ImgFormat fmt = GetImageFormat(path);

            try
            {
                switch (fmt)
                {
                case ImgFormat.png:
                    PNG png = new PNG();
                    png.Load(path);
                    return(png);

                case ImgFormat.bmp:
                    BMP bmp = new BMP();
                    bmp.Load(path);
                    return(bmp);

                case ImgFormat.gif:
                    Gif gif = new Gif();
                    gif.Load(path);
                    return(gif);

                case ImgFormat.jpg:
                    JPEG jpeg = new JPEG();
                    jpeg.Load(path);
                    return(jpeg);

                case ImgFormat.tif:
                    TIFF tiff = new TIFF();
                    tiff.Load(path);
                    return(tiff);

                case ImgFormat.webp:
                    Webp webp = new Webp();
                    webp.Load(path);
                    return(webp);

                case ImgFormat.wrm:
                    WORM worm = new WORM();
                    worm.Load(path);
                    return(worm);

                case ImgFormat.ico:
                    ICO ico = new ICO();
                    ico.Load(path);
                    return(ico);
                }
            }
            catch (Exception e)
            {
                if (showError)
                {
                    e.ShowError();
                }
            }
            return(null);
        }
示例#19
0
        /// <summary>
        /// Loads an image.
        /// </summary>
        /// <param name="path"> The path to the image. </param>
        /// <returns> A bitmap object if the image is loaded, otherwise null. </returns>
        public static Bitmap LoadImageAsBitmap(string path, bool showError = false)
        {
            if (string.IsNullOrEmpty(path) || !File.Exists(path))
            {
                return(null);
            }

            ImgFormat fmt = GetImageFormat(path);

            if (fmt == ImgFormat.nil)
            {
                fmt = GetImageFormatFromPath(path);
            }

            try
            {
                Bitmap result;

                switch (fmt)
                {
                case ImgFormat.png:
                    result     = PNG.FromFileAsBitmap(path);
                    result.Tag = ImgFormat.png;
                    return(result);

                case ImgFormat.bmp:
                    result     = BMP.FromFileAsBitmap(path);
                    result.Tag = ImgFormat.bmp;
                    return(result);

                case ImgFormat.gif:
                    result     = Gif.FromFileAsBitmap(path);
                    result.Tag = ImgFormat.gif;
                    return(result);

                case ImgFormat.jpg:
                    result     = JPEG.FromFileAsBitmap(path);
                    result.Tag = ImgFormat.jpg;
                    return(result);

                case ImgFormat.tif:
                    result     = TIFF.FromFileAsBitmap(path);
                    result.Tag = ImgFormat.tif;
                    return(result);

                case ImgFormat.webp:
                    result     = Webp.FromFileAsBitmap(path);
                    result.Tag = ImgFormat.webp;
                    return(result);

                case ImgFormat.wrm:
                    result     = WORM.FromFileAsBitmap(path);
                    result.Tag = ImgFormat.wrm;
                    return(result);

                case ImgFormat.ico:
                    result     = ICO.FromFileAsBitmap(path);
                    result.Tag = ImgFormat.ico;
                    return(result);
                }
            }
            catch (Exception e)
            {
                if (showError)
                {
                    e.ShowError();
                }
            }
            return(null);
        }
示例#20
0
        /// <summary>
        /// Opens a save file dialog asking where to save an image.
        /// </summary>
        /// <param name="img"> The image to save. </param>
        /// <param name="path"> The path to open. </param>
        /// <param name="collectGarbage"> A bool indicating if GC.Collect should be called after saving. </param>
        /// <returns> The filename of the saved image, null if failed to save or canceled. </returns>
        public static string SaveImageFileDialog(Image img, string path = "", bool collectGarbage = true)
        {
            using (SaveFileDialog sfd = new SaveFileDialog())
            {
                sfd.Title      = InternalSettings.Save_File_Dialog_Title;
                sfd.Filter     = InternalSettings.Image_Dialog_Filters;
                sfd.DefaultExt = "png";

                if (!string.IsNullOrEmpty(path))
                {
                    sfd.FileName = Path.GetFileName(path);

                    ImgFormat fmt = GetImageFormatFromPath(path);

                    if (fmt != ImgFormat.nil)
                    {
                        switch (fmt)
                        {
                        case ImgFormat.png:
                            sfd.FilterIndex = 1;
                            break;

                        case ImgFormat.jpg:
                            sfd.FilterIndex = 2;
                            break;

                        case ImgFormat.bmp:
                            sfd.FilterIndex = 3;
                            break;

                        case ImgFormat.tif:
                            sfd.FilterIndex = 4;
                            break;

                        case ImgFormat.gif:
                            sfd.FilterIndex = 5;
                            break;

                        case ImgFormat.wrm:
                            sfd.FilterIndex = 6;
                            break;

                        case ImgFormat.webp:
                            if (InternalSettings.WebP_Plugin_Exists)
                            {
                                sfd.FilterIndex = 7;
                                break;
                            }
                            sfd.FilterIndex = 2;
                            break;
                        }
                    }
                }

                if (sfd.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(sfd.FileName))
                {
                    SaveImage(img, sfd.FileName, collectGarbage);
                    return(sfd.FileName);
                }
            }

            return(null);
        }
示例#21
0
        /// <summary>
        /// 获取ContentType
        /// </summary>
        /// <param name="format"></param>
        /// <param name="defaultContentType"></param>
        /// <returns></returns>
        public static string GetContentType(this ImgFormat format, string defaultContentType = "image/jpeg")
        {
            string contentType;

            switch (format)
            {
            case ImgFormat.Bmp:
            {
                contentType = ContentTypeHelper.ImageBmp;
                break;
            }

            case ImgFormat.Gif:
            {
                contentType = ContentTypeHelper.ImageGif;
                break;
            }

            case ImgFormat.Jpg:
            {
                contentType = ContentTypeHelper.ImageJpg;
                break;
            }

            case ImgFormat.Png:
            {
                contentType = ContentTypeHelper.ImagePng;
                break;
            }

            case ImgFormat.Tiff:
            {
                contentType = ContentTypeHelper.ImageTiff;
                break;
            }

            case ImgFormat.Svg:
            {
                contentType = ContentTypeHelper.ImageSvg;
                break;
            }

            case ImgFormat.Pdf:
            {
                contentType = ContentTypeHelper.ApplicationPdf;
                break;
            }

            case ImgFormat.Psd:
            {
                contentType = ContentTypeHelper.ApplicationPsd;
                break;
            }

            case ImgFormat.Ico:
            {
                contentType = ContentTypeHelper.ImageIcon;
                break;
            }

            case ImgFormat.Cur:
            {
                contentType = ContentTypeHelper.ImageCur;
                break;
            }

            default:
            {
                contentType = defaultContentType;
                break;
            }
            }

            return(contentType);
        }
示例#22
0
		void Init (int w, int h, ImgFormat fmt);
示例#23
0
        private static void Test(List <string> error, string pathName, int width, int height, ImgFormat format)
        {
            var img = ImageHelper.GetImageInfo($"{Dir}{pathName}");
            var b   = img.Width == 0 && img.Height == 0
                ? img.ImageFormat == format
                : img.ImageFormat == format && img.Width == width && img.Height == height;

            if (!b)
            {
                error.Add($"{width}*{height};{pathName}");
            }
        }
        private int SaveFileInTempFolder(string url, int imgCt, ImgFormat frmt)
        {
            if (!Directory.Exists(tmpFileLocation))
                Directory.CreateDirectory(tmpFileLocation);

            return DownloadFileTypesFromURL(url, imgCt, frmt);
        }
示例#25
0
        private void OpenFile_btn_Click(object sender, EventArgs e)
        {
            if (Functional_Tab.SelectedTab == Convert_Img_Page)
            {
                if (SelectMultipleFiles_radbtn.Checked)
                {
                    using (var OpenFolder = new FolderBrowserDialog())
                    {
                        if (OpenFolder.ShowDialog() == DialogResult.OK)
                        {
                            SaveImg_btn.Enabled = true;
                            string images_directory = OpenFolder.SelectedPath;
                            txtPathFile.Text = OpenFolder.SelectedPath;

                            try
                            {
                                if (Directory.Exists(images_directory))
                                {
                                    foreach (string file in Directory.GetFiles(images_directory))
                                    {
                                        var Extension_selected = ImgExtension.SelectedItem;
                                        switch (Extension_selected)
                                        {
                                        case "PNG":
                                            ImgFormat.ToPng(file, images_directory);
                                            break;

                                        case "JPG":
                                            ImgFormat.ToJpg(file, images_directory);
                                            break;

                                        case "ICO":
                                            //ImgFormat.ToIco(file, images_directory);
                                            break;

                                        case "BMP":
                                            ImgFormat.ToBmp(file, images_directory);
                                            break;

                                        case "TIFF":
                                            ImgFormat.ToTiff(file, images_directory);
                                            break;
                                        }
                                    }
                                    //MessageBox.Show("Все файлы успешно сконвертированы", "Успех!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                            }
                            catch
                            {
                                MessageBox.Show("Неверный формат файла", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                }
                else if (SelectOneFile_radbtn.Checked)
                {
                    using (var OpenFolder = new OpenFileDialog())
                    {
                        OpenFolder.Filter = "Image Files(*.PNG;*.JPG;*.BMP;*.ICO;*.TIFF)|*.PNG;*.JPG;*.BMP;*.ICO;*.TIFF|All files(*.*)|*.*";

                        if (OpenFolder.ShowDialog() == DialogResult.OK)
                        {
                            SaveImg_btn.Enabled = true;

                            image_directory  = OpenFolder.FileName;
                            txtPathFile.Text = image_directory;
                        }
                    }
                }
            }
            else if (Functional_Tab.SelectedTab == Edit_Img_Page)
            {
                OpenFile_btn.Enabled = true;

                using (var OpenFile = new OpenFileDialog())
                {
                    OpenFile.Filter = "Image Files(*.JPG)|*.JPG";
                    if (OpenFile.ShowDialog() == DialogResult.OK)
                    {
                        SaveImg_btn.Enabled = true;
                        image_directory     = OpenFile.FileName;
                        Picture             = new Bitmap(image_directory);
                        PictureBox.Image    = Picture;
                    }
                }
            }
        }
示例#26
0
        /// <summary>
        /// Generates a placeholder image via the http://placehold.it web service
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="text"></param>
        /// <param name="backgroundColor"></param>
        /// <param name="textColor"></param>
        /// <param name="format"></param>
        /// <returns>Returns an HTML image element with the specified parameters</returns>
        public static MvcHtmlString Placehold(this HtmlHelper html, int width, int height, string text = null, string backgroundColor = null, string textColor = null, object htmlAttributes = null, ImgFormat format = ImgFormat.GIF)
        {
            var placeholder = new TagBuilder("img");
            var options     = new StringBuilder();

            placeholder.MergeAttributes(htmlAttributes != null ? HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes) : null);
            options.AppendFormat(format == ImgFormat.GIF ? "" : ".{0}", format);
            options.AppendFormat(backgroundColor != null ? "/{0}" : "", backgroundColor);
            options.AppendFormat(textColor != null ? "/{0}" : "", textColor);
            options.AppendFormat(text != null ? "&text={0}" : "", text);
            placeholder.Attributes.Add("src", string.Format("http://placehold.it/{0}x{1}{2}", width, height, options));
            return(MvcHtmlString.Create(placeholder.ToString(TagRenderMode.SelfClosing)));
        }
示例#27
0
        private static void UpdateTextureData(Texture2D texture, TextureData textureData, ImgFormat imgFormat)
        {
            // Fill image colors per pixel
            Color[] colorList      = new Color[textureData.width * textureData.height];
            int     positionOffset = 0;

            // Flip image pixels due to Unity SetPixels texture method flipping the image
            // First color in the color list will be the last pixel in the image
            // and the resulting image will be flipped and mirrored
            for (int height = textureData.height - 1; height >= 0; height--)
            {
                for (int width = 0; width < textureData.width; width++)
                {
                    int pixelIndex = height * textureData.width + width;
                    // Convert STP image format to Unity texture format
                    switch (imgFormat)
                    {
                    case ImgFormat.RawRGBA:
                        colorList[pixelIndex].r = MarshalData.GetByteFromUnmanagedArray(textureData.imgData, positionOffset) / 255.0f;
                        positionOffset         += MarshalData.sizeOfByte;
                        colorList[pixelIndex].g = MarshalData.GetByteFromUnmanagedArray(textureData.imgData, positionOffset) / 255.0f;
                        positionOffset         += MarshalData.sizeOfByte;
                        colorList[pixelIndex].b = MarshalData.GetByteFromUnmanagedArray(textureData.imgData, positionOffset) / 255.0f;
                        positionOffset         += MarshalData.sizeOfByte;
                        colorList[pixelIndex].a = MarshalData.GetByteFromUnmanagedArray(textureData.imgData, positionOffset) / 255.0f;
                        positionOffset         += MarshalData.sizeOfByte;
                        break;

                    case ImgFormat.RawRGB:
                        colorList[pixelIndex].r = MarshalData.GetByteFromUnmanagedArray(textureData.imgData, positionOffset) / 255.0f;
                        positionOffset         += MarshalData.sizeOfByte;
                        colorList[pixelIndex].g = MarshalData.GetByteFromUnmanagedArray(textureData.imgData, positionOffset) / 255.0f;
                        positionOffset         += MarshalData.sizeOfByte;
                        colorList[pixelIndex].b = MarshalData.GetByteFromUnmanagedArray(textureData.imgData, positionOffset) / 255.0f;
                        positionOffset         += MarshalData.sizeOfByte;
                        break;

                    case ImgFormat.RawGray:
                        colorList[pixelIndex].r = MarshalData.GetByteFromUnmanagedArray(textureData.imgData, positionOffset) / 255.0f;
                        positionOffset         += MarshalData.sizeOfByte;
                        break;
                    }
                }
            }
            texture.SetPixels(colorList);
            texture.Apply(true);
        }