示例#1
0
        public async Task <IActionResult> CreateImgPost()
        {
            ImgData Img = new ImgData();

            if (await TryUpdateModelAsync(Img))
            {
                try
                {
                    await Img.AddTo(_context);
                }
                catch (ArgumentException)
                {
                    return(NotFound());
                }
            }

            return(RedirectToAction("IndexImg",
                                    routeValues: new
            {
                Img.KingdomID,
                Img.PhylumID,
                Img.ClassID,
                Img.OrderID,
                Img.FamilyID,
                Img.GenusID,
                Img.SpeciesID
            }));
        }
示例#2
0
    public void GetSexy()
    {
        if (state != STATE.NONE)
        {
            return;
        }
        state = STATE.Loading;
        ImgData d = AssetDatabase.LoadAssetAtPath(ASSETS_PATH, typeof(ImgData)) as ImgData;

        if (d == null)
        {
            d = ScriptableObject.CreateInstance <ImgData>();
            AssetDatabase.CreateAsset(d, ASSETS_PATH);
        }

        if (d == null)
        {
            return;
        }
        items = d.imgs;
        Thread t = new Thread(GetImgBytes);

        t.Start();
        firstTime = false;
    }
示例#3
0
        public async Task <ImgData> GetImg(Loids loid, int size = 0)
        {
            WebClient wc      = new WebClient();
            string    ApiJson = await wc.DownloadStringTaskAsync($"https://api.meek.moe/{GetLoid(loid)}");

            ApiResponse  ar = JsonConvert.DeserializeObject <ApiResponse>(ApiJson);;
            MemoryStream im;

            if (size < 0)
            {
                im = new MemoryStream(await wc.DownloadDataTaskAsync(ar.Url))
                {
                    Position = 0
                };
            }
            else
            {
                im = new MemoryStream(await wc.DownloadDataTaskAsync($"https://api.meek.moe/im/?image={ar.Url}&resize={size}"))
                {
                    Position = 0
                };
            }
            ImgData iu = new ImgData
            {
                Url      = ar.Url,
                ProxyUrl = $"https://api.meek.moe/im/?image={ar.Url}&resize=500",
                Creator  = ar.Creator,
                Image    = im,
                FileType = MimeGuesser.GuessExtension(im)
            };

            return(iu);
        }
示例#4
0
    public void Update()
    {
        if (state == STATE.LoadComplete)
        {
            ImgData d    = AssetDatabase.LoadAssetAtPath(ASSETS_PATH, typeof(ImgData)) as ImgData;
            ImgData newd = ScriptableObject.Instantiate(d) as ImgData;
            newd.hideFlags = HideFlags.DontSave;
            newd.imgs      = items;
            newd.hideFlags = 0;
            AssetDatabase.CreateAsset(newd, ASSETS_PATH);
            AssetDatabase.SaveAssets();

            state = STATE.NONE;
            if (callback != null)
            {
                callback(textureBytes);
            }
        }

        if (maxCount != -1)
        {
            random   = UnityEngine.Random.Range(0, maxCount);
            maxCount = -1;
        }
    }
示例#5
0
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="file">文件流</param>
        /// <param name="iisRootPath">IIS本地文件夹路径</param>
        public static ImgData ImageUpload(HttpPostedFileBase file, string iisRootPath)
        {
            var result = new ImgData();

            if (file != null && file.ContentLength > 0)
            {
                try
                {
                    var generateFolder = DateTime.Now.ToString(CommonConstant.DateTimeFormatDayOnly);
                    //随机文件名
                    var generateFileName = string.Format("{0}{1}", Guid.NewGuid().ToString("N"), Path.GetExtension(file.FileName));
                    //相对路径(\Imgaes\XXXX)
                    var localPath = string.Format("{0}{1}", "\\Images\\", generateFolder);
                    //保存本地路径(D:\XXX\Imgaes\XXXX)
                    var uploadFolder = string.Format("{0}{1}", iisRootPath, localPath);
                    //保存图片地址(D:\XXX\Imgaes\XXXX\XXX.JPG)
                    var savepath = string.Format("{0}\\{1}", uploadFolder, generateFileName);
                    if (!Directory.Exists(uploadFolder))
                    {
                        Directory.CreateDirectory(uploadFolder);
                    }
                    file.SaveAs(savepath);
                    //图片URL(http://XXXX/XXX/XXX.JPG)
                    var imgUrl = string.Format("{0}{1}{2}/{3}", ServerInfo.RootURI, "Images/", generateFolder, generateFileName);
                    result.ImgLocalPath = string.Format("{0}\\{1}", localPath, generateFileName);
                    result.ImgName      = generateFileName;
                    result.ImgUrl       = imgUrl;
                }
                catch (Exception)
                {
                }
            }
            return(result);
        }
示例#6
0
        //网络图片本地化上传
        /// <param name="imgUrl">图片网络地址</param>
        /// <param name="formatType">剪裁方式</param>
        /// <param name="width">宽</param>
        /// <param name="high">高</param>
        public static ImgData doImgUpLoad(string imgUrl, ImgFormatType formatType = ImgFormatType.ScaleWith, int width = 500, int high = 800)
        {
            ImgData data = new ImgData();

            //开始处理图片相关
            if (!string.IsNullOrEmpty(imgUrl) && (imgUrl.StartsWith("http://") || imgUrl.StartsWith("https://")))
            {
                //开始上传图片
                ImgUploadRet imgRet = ImgUtil.UploadImag(imgUrl, new ImgFormat(1, formatType, width, high));
                if (imgRet.IsSuc)
                {
                    data.img_default  = imgRet.GetImgUrl(0); //本地化原尺寸地址
                    data.img_specify  = imgRet.GetImgUrl(1); //本地化后生成的指定规格 300*225后的地址
                    data.img_original = imgUrl;
                    //_logger.Error("----doImgUpLoad--- img_original: " + imgUrl + " img_default:" + data.img_default + " img_specify:"+data.img_specify);
                }
                else //失败
                {
                    data.img_default  = ""; //
                    data.img_specify  = ""; //
                    data.img_original = imgUrl;
                }
            }

            return(data);
        }
示例#7
0
        /// <summary>
        /// 文本中的图片本地化
        /// </summary>
        /// <param name="content">文本内容</param>
        /// <returns>new_content</returns>
        public static string LocalizationImgInTxt(string content)
        {
            Regex         reg       = new Regex(@"<img[^>]*(data-)?src=['""\s]*([^\s'""]+)[^>]*>");
            List <string> imageList = new List <string>();

            MatchCollection matches = reg.Matches(content);

            foreach (Match m in matches)
            {
                string url = reg.Replace(m.Value, "$2");
                if (!string.IsNullOrEmpty(url) && (url.StartsWith("http://") || url.StartsWith("https://")))
                {
                    if (imageList.IndexOf(url) == -1)
                    {
                        imageList.Add(url);

                        ImgData imgObj = doImgUpLoad(url);
                        string  newurl = imgObj.img_default;
                        content = content.Replace(m.Value, string.Format("<img src=\"{0}\" />", newurl));
                    }
                    else
                    {
                        //_logger.Error("----LocalizationImgInTxt---11111111111 url: " + url);
                    }
                }
                else
                {
                    //_logger.Error("----LocalizationImgInTxt---2222222222 url: " + url);
                }
            }

            return(content);
        }
示例#8
0
        //=CREATE=IMG==========================================================

        // GET: Organism/CreateImg
        public async Task <IActionResult> CreateImg()
        {
            ImgData Img = new ImgData();

            await TryUpdateModelAsync(Img);

            return(View(Img));
        }
示例#9
0
    internal void DelCache()
    {
        ImgData d    = AssetDatabase.LoadAssetAtPath(ASSETS_PATH, typeof(ImgData)) as ImgData;
        ImgData newd = ScriptableObject.Instantiate(d) as ImgData;

        newd.hideFlags = HideFlags.DontSave;
        newd.imgs.Clear();
        newd.hideFlags = 0;
        AssetDatabase.CreateAsset(newd, ASSETS_PATH);
        AssetDatabase.SaveAssets();
        items.Clear();
    }
示例#10
0
        public void LoadTextureFromPixels32()
        {
            //There is loaded pixels
            if (mTextureID == 0 && ImgData != null)
            {
                mTextureID = GL.GenTexture();

                GL.BindTexture(TextureTarget.Texture2D, mTextureID);

                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, ImgData.Width, ImgData.Height, 0,
                              OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, ImgData.Scan0);

                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMinFilter.Nearest);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);

                GL.BindTexture(TextureTarget.Texture2D, 0);

                ErrorCode error = GL.GetError();

                if (error != 0)
                {
                    throw new Exception("Error loading texture from " + ImgData.ToString() + "! " + error.ToString());
                }
                else
                {
                    //Release pixels

                    mBitmap.UnlockBits(ImgData);
                    ImgData = null;
                }

                //Generate VBO
                initVBO();
            }
            else
            {
                //Texture already exists
                if (mTextureID != 0)
                {
                    throw new Exception("A texture is already loaded!");
                }
                //No pixel loaded
                else if (ImgData == null)
                {
                    throw new Exception("No pixels to create texture from!");
                }
            }
        }
示例#11
0
 public ActionResult Post([FromBody]ImgData imgData)
 {
     string rootDirectory = AppContext.BaseDirectory;
     string filePath = Base64BitmapUtil.SaveLocal(imgData.Base64);
     string tessDataPath = $"{rootDirectory}tessdata";
     using (var engine = new TesseractEngine(tessDataPath, "chi_sim", EngineMode.Default))
     {
         using (var pix = Pix.LoadFromFile(filePath))
         {
             using (var page = engine.Process(pix))
             {
                 string text = page.GetText();
                 return Ok(text);
             }
         }
     }
 }
示例#12
0
        // GET: Img/DeleteImg/5
        public async Task <IActionResult> DeleteImg()
        {
            ImgData Img = new ImgData();

            await TryUpdateModelAsync(Img);

            await Img.Delete(_context);

            return(RedirectToAction("IndexImg",
                                    routeValues: new
            {
                Img.KingdomID,
                Img.PhylumID,
                Img.ClassID,
                Img.OrderID,
                Img.FamilyID,
                Img.GenusID,
                Img.SpeciesID
            }));
        }
            ImgData ParseImageData(string s)
            {
                var chars = s.ToCharArray ();

                var data = new ImgData ();

                for (var i = 0; i < chars.Length; i++)
                {
                    var c = chars[i];

                    if (c == TokenizedSpans.naked_url_sigil[0])
                    {
                        var sub = chars.Skip (i).Take (TokenizedSpans.naked_url_sigil.Length).ToArray();

                        var equal = sub.SequenceEqual (TokenizedSpans.naked_url_sigil);

                        if (equal)
                        {
                            i = i + sub.Length;

                            var path = new List<char> ();

                            while (i < chars.Length && !char.IsWhiteSpace (chars[i]))
                            {
                                var k = chars[i];
                                i++;

                                if (k == '\\')
                                    break;
                                else

                                path.Add (k);
                            }

                            data.Path = new string (path.ToArray ());
                        }
                    }

                    if (c == '"')
                    {
                        var sub = chars.Skip(i).ToArray();

                        if (sub.Length > 1 && sub.Contains('"'))
                        {
                            var title = new List<char> ();

                            while (++i < chars.Length && chars[i] != '"')
                            {
                                title.Add (chars[i]);
                            }

                            data.Title = new string (title.ToArray ());
                        }
                    }
                    else
                    if (!char.IsWhiteSpace (c) && data.Path == null)
                    {
                        var _path = new List<char> ();

                        while (i < chars.Length && !char.IsWhiteSpace (chars[i]) && chars[i] != ']' && chars[i] != '"')
                        {
                            _path.Add (chars[i]);
                            i++;
                        }

                        data.Path = Parsed.RelativeMediaPath + new string (_path.ToArray ());
                    }
                }

                return data;
            }
示例#14
0
		/// <summary> Instantiates the ImgDataAdapter object specifying the ImgData source.
		/// 
		/// </summary>
		/// <param name="src">From where to obtain all the ImgData values.
		/// 
		/// </param>
		protected internal ImgDataAdapter(ImgData src)
		{
			imgdatasrc = src;
		}
示例#15
0
        /// <summary> Initializes the header writer with the references to the coding chain.
        /// 
        /// </summary>
        /// <param name="origsrc">The original image data (before any component mixing,
        /// tiling, etc.)
        /// 
        /// </param>
        /// <param name="isorigsig">An array specifying for each component if it was
        /// originally signed or not.
        /// 
        /// </param>
        /// <param name="dwt">The discrete wavelet transform module.
        /// 
        /// </param>
        /// <param name="tiler">The tiler module.
        /// 
        /// </param>
        /// <param name="encSpec">The encoder specifications
        /// 
        /// </param>
        /// <param name="roiSc">The ROI scaler module.
        /// 
        /// </param>
        /// <param name="ralloc">The post compression rate allocator.
        /// 
        /// </param>
        /// <param name="pl">ParameterList instance.
        /// 
        /// </param>
        public HeaderEncoder(ImgData origsrc, bool[] isorigsig, ForwardWT dwt, Tiler tiler, EncoderSpecs encSpec, ROIScaler roiSc, PostCompRateAllocator ralloc, ParameterList pl)
        {
            pl.checkList(OPT_PREFIX, CSJ2K.j2k.util.ParameterList.toNameArray(pinfo));
            if (origsrc.NumComps != isorigsig.Length)
            {
                throw new System.ArgumentException();
            }
            this.origSrc = origsrc;
            this.isOrigSig = isorigsig;
            this.dwt = dwt;
            this.tiler = tiler;
            this.encSpec = encSpec;
            this.roiSc = roiSc;
            this.ralloc = ralloc;

            baos = new System.IO.MemoryStream();
            //UPGRADE_TODO: Class 'java.io.DataOutputStream' was converted to 'System.IO.BinaryWriter' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataOutputStream'"
            hbuf = new CSJ2K.Util.EndianBinaryWriter(baos, true);
            nComp = origsrc.NumComps;
            enJJ2KMarkSeg = pl.getBooleanParameter("Hjj2000_COM");
            otherCOMMarkSeg = pl.getParameter("HCOM");
        }
示例#16
0
文件: ForwardWT.cs 项目: IMA-DZ/LMV
 /// <summary> Initializes this object for the specified number of tiles 'nt' and
 /// components 'nc'.
 ///
 /// </summary>
 /// <param name="src">The source of ImgData
 ///
 /// </param>
 protected internal ForwardWT(ImgData src) : base(src)
 {
 }
示例#17
0
 /// <summary> Instantiates the ImgDataAdapter object specifying the ImgData source.
 ///
 /// </summary>
 /// <param name="src">From where to obtain all the ImgData values.
 ///
 /// </param>
 protected internal ImgDataAdapter(ImgData src)
 {
     imgdatasrc = src;
 }
示例#18
0
		/// <summary> Initializes this object for the specified number of tiles 'nt' and
		/// components 'nc'.
		/// 
		/// </summary>
		/// <param name="src">The source of ImgData
		/// 
		/// </param>
		protected internal ForwardWT(ImgData src):base(src)
		{
		}
示例#19
0
        public ImgData GetStat(string file)
        {
            ImgData outputData = new ImgData();
            var     stopwatch  = new System.Diagnostics.Stopwatch();

            stopwatch.Start();
            stopwatch.Restart();

            Bitmap     bitmap    = new Bitmap(file);
            LockBitmap lockedBmp = new LockBitmap(bitmap);

            lockedBmp.LockBits();

            float TotalHue = 0.0f;
            float TotalSat = 0.0f;
            float TotalVal = 0.0f;

            float MaxHue = 0f;
            float MaxSat = 0f;
            float MaxVal = 0f;

            float MinHue = 100f;
            float MinSat = 100f;
            float MinVal = 100f;

            for (int x = 0; x < lockedBmp.Width; x++)
            {
                for (int y = 0; y < lockedBmp.Height; y++)
                {
                    var   Pixel = lockedBmp.GetPixel(x, y);
                    float hue   = Pixel.GetHue();
                    float value = Pixel.GetBrightness();
                    float sat   = lockedBmp.GetPixel(x, y).GetSaturation();


                    TotalHue += hue;
                    TotalSat += sat;
                    TotalVal += value;

                    //Set the
                    if (hue > MaxHue)
                    {
                        MaxHue = hue;
                    }
                    if (sat > MaxSat)
                    {
                        MaxSat = sat;
                    }
                    if (value > MaxVal)
                    {
                        MaxVal = value;
                    }

                    if (hue < MinHue)
                    {
                        MinHue = hue;
                    }
                    if (sat < MinSat)
                    {
                        MinSat = sat;
                    }
                    if (value < MinVal)
                    {
                        MinVal = value;
                    }

                    /*Just so I could make the cool little spinny thing
                     * Also because I need to know if the program is working or not.
                     * Console.Write("\r" + processChar[(int)processCharIndex]);
                     * processCharIndex += 0.001f;
                     * if (processCharIndex >= processChar.Length)
                     *{
                     *    processCharIndex = 0;
                     * }
                     */
                }
            }
            lockedBmp.UnlockBits();

            //TODO: Remove this ⬇
            Console.Write("\n");
            Console.Write($"Totals (HSV): {TotalHue}, {TotalSat}, {TotalVal}; \n" +
                          $"Mean        : {TotalHue / (lockedBmp.Width * lockedBmp.Height)}, {TotalSat / (lockedBmp.Width * lockedBmp.Height)}, {TotalVal / (lockedBmp.Width * lockedBmp.Height)} \n" +
                          $"Min         : {MinHue}, {MinSat}, {MinVal} \n" +
                          $"Max         : {MaxHue}, {MaxSat}, {MaxVal} \n");

            Console.WriteLine($"\n Processing Time: {stopwatch.Elapsed}");
            stopwatch.Stop();

            totalElapsedMS += stopwatch.ElapsedMilliseconds;

            /*
             * Doing this to keep memory usage down--
             * haven't seen any negative effects so far,
             * but I will have to see if data is being
             * modified unintentionally.
             */
            GC.Collect();

            int totalPixels = lockedBmp.Width * lockedBmp.Height;

            //Max
            outputData.MaxHue = MaxHue;
            outputData.MaxSat = MaxSat;
            outputData.MaxVal = MaxVal;

            //Min
            outputData.MinHue = MinHue;
            outputData.MinSat = MinSat;
            outputData.MinVal = MinVal;

            //Mean
            outputData.MeanHue = TotalHue / totalPixels;
            outputData.MeanSat = TotalSat / totalPixels;
            outputData.MeanVal = TotalVal / totalPixels;

            //Totals
            outputData.TotalHue = TotalHue;
            outputData.TotalSat = TotalSat;
            outputData.TotalVal = TotalVal;

            return(outputData);
        }