Exemple #1
0
        public void TestMethod7()
        {
            var path = $"{FileDir}base64.jpg";
            var b    = ImageHelper.ImageToBase64String(path, out var str);

            Assert.IsTrue(b);

            var res = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCADcANwDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD3aiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAorx74hfGXUPBni6fRrfSbW5jjjRxJJIwJ3DPauW/4aP1f/AKAFj/39egD6Kor51/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ain.CurrentDomain.BaseDirectory}/{Guid.NewGuid()}.jpg";
            var b2     = ImageHelper.Base64StringToImage(str, toPath);

            Assert.IsTrue(b2);

            var md1 = EncryptionHelper.FileMd5(path);
            var md2 = EncryptionHelper.FileMd5(toPath);

            FileHelper.DeleteFile(toPath, false);

            var b3 = md1.IsEquals(md2);

            if (!b3)
            {
                Assert.Inconclusive("两文件的md5值不一样");
            }

            Assert.IsTrue(b3);
        }
Exemple #2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Image bitMapOn  = null;
            Image bitMapOff = null;

            if (checkStyle == CheckStyle.iOS)
            {
                bitMapOn  = ImageHelper.Base64StringToImage(btncheckon1);
                bitMapOff = ImageHelper.Base64StringToImage(btncheckoff1);
            }
            else if (checkStyle == CheckStyle.Android)
            {
                bitMapOn  = ImageHelper.Base64StringToImage(btncheckon2);
                bitMapOff = ImageHelper.Base64StringToImage(btncheckoff2);
            }

            Graphics  g   = e.Graphics;
            Rectangle rec = new Rectangle(0, 0, this.Size.Width, this.Size.Height);

            if (isCheck)
            {
                g.DrawImage(bitMapOn, rec);
            }
            else
            {
                g.DrawImage(bitMapOff, rec);
            }
        }
        public IActionResult SaveImageCode(string access_token)
        {
            try
            {
                int systemId = SystemID;
                if (!IsAccessToken(access_token))
                {
                    return(Error("验证token失败!"));
                }
                var entity = AccountService.GetAccountByAccessTokenPro(systemId, access_token);
                if (entity == null)
                {
                    return(Error("验证会员资料失败!"));
                }
                if (string.IsNullOrEmpty(entity.CompanyID))
                {
                    return(Error("验证会员资料失败!"));
                }
                string companyId = entity.CompanyID;
                string memberId  = entity.MemberID;

                string base64String = Accessor.HttpContext.Request.GetInputStream();
                string imageCode    = ImageHelper.GetImageCode(base64String);
                long   fileSize     = imageCode.Length;
                string fileName     = string.Format("{0}.{1}", GeneralCodeHelper.GetRandomInt(8), ImageHelper.GetImageExtension(base64String));
                string uploadPath   = CreateUploadPath(systemId, companyId, fileName);
                string newFileName  = CreateFileName(fileName);
                var    filePath     = string.Format("{0}\\{1}", uploadPath, newFileName);
                string src          = ToRelativePath(filePath);
                string url          = ToAbsoluteUri(filePath);
                string mediaId      = PrimaryKeyHelper.MakePrimaryKey(PrimaryKeyHelper.PrimaryKeyType.BasicsMedia);
                var    media        = new Ld_Basics_Media()
                {
                    SystemID      = systemId,
                    CompanyID     = companyId,
                    MediaID       = mediaId,
                    FileName      = fileName,
                    FileExtension = Path.GetExtension(fileName).ToLower(),
                    FileSize      = fileSize,
                    Url           = url,
                    Src           = src,
                };
                var data = new { mediaid = mediaId, name = fileName, size = fileSize, url, src };
                if (fileSize > 0)
                {
                    string savePath = ImageHelper.Base64StringToImage(filePath, base64String);
                }
                int result = MediaService.SaveMediaMember(memberId, media);
                if (result > 0)
                {
                    return(Success("ok", new { count = 1, size = fileSize, file = data }));
                }
                else
                {
                    return(Error("upload fail!"));
                }
            }
            catch (Exception ex)
            {
                return(Error(ex.Message));
            }
        }
Exemple #4
0
        private void DrawMetallicStyle(PaintEventArgs e)
        {
            e.Graphics.SmoothingMode   = SmoothingMode.HighQuality;
            e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

            Rectangle r = new Rectangle(0, 0, this.Width, this.Height);

            contentRectangle = r;
            if (!isMouseMoved)
            {
                if (this.ToggleState == ToggleButtonState.ON)
                {
                    ipadx = this.contentRectangle.Right - (this.contentRectangle.Height - 3);
                }
                else
                {
                    ipadx = 2;
                }
            }
            Rectangle rect = new Rectangle(ipadx, r.Y, r.Height - 5, r.Height);
            Rectangle r2   = new Rectangle(this.Width / 6 - 10, this.Height / 2, (this.Width / 6 - 10) + (rect.X + rect.Width / 2), this.Height / 2);

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            int d = this.Height;

            gp.AddArc(r.X, r.Y, d, d, 180, 90);
            gp.AddArc(r.X + r.Width - d, r.Y, d, d, 270, 90);
            gp.AddArc(r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90);
            gp.AddArc(r.X, r.Y + r.Height - d, d, d, 90, 90);
            this.Region = new Region(gp);


            if (ipadx < contentRectangle.Width / 2)
            {
                iosSelected = false;
            }
            else if (ipadx == contentRectangle.Right - (contentRectangle.Height - 3) || ipadx > contentRectangle.Width / 2)
            {
                iosSelected = true;
            }

            Rectangle ar1 = new Rectangle(r.X, r.Y, r.X + rect.Right, r.Height);
            Rectangle ar2 = new Rectangle(rect.X + rect.Width / 2, r.Y, (rect.X + rect.Width / 2) + r.Right, r.Height);

            SolidBrush br = new SolidBrush(this.ActiveColor);

            e.Graphics.FillRectangle(br, ar1);

            #region Inactive path

            br = new SolidBrush(this.InActiveColor);
            e.Graphics.FillRectangle(br, ar2);

            #endregion

            if (iosSelected)
            {
                e.Graphics.DrawString(this.ActiveText, Font, new SolidBrush(TextColor), new PointF(contentRectangle.X + 8, contentRectangle.Y + (contentRectangle.Height / 4)));
            }
            else
            {
                e.Graphics.DrawString(this.InActiveText, Font, new SolidBrush(TextColor), new PointF(rect.Right + 5, contentRectangle.Y + (contentRectangle.Height / 4)));
            }



            #region Center Ellipse
            Color      c   = this.Parent != null ? this.Parent.BackColor : Color.White;
            SolidBrush br2 = new SolidBrush(InActiveColor);
            if (this.ToggleState == ToggleButtonState.ON)
            {
                br2.Color = this.ActiveColor;
            }
            e.Graphics.DrawEllipse(new Pen(br2.Color), rect);
            e.Graphics.FillEllipse(br2, rect);
            #endregion

            e.Graphics.DrawPath(new Pen(c, 2f), gp);
            if (!this.DesignMode)
            {
                Image img = ImageHelper.Base64StringToImage(ScrewBase64StringImage);
                e.Graphics.DrawImage(img, rect);
                img.Dispose();
            }
        }