예제 #1
0
        public JsonResult <object> UploadImage([FromBody] string imgBase64)
        {
            var    baseInfo = GetBaseInfo();
            string fileName = Guid.NewGuid().ToString().Replace("-", "");
            var    filePath = ImageHelp.CreateImage(imgBase64, fileName, "upload");

            return(JsonNet(filePath));
        }
예제 #2
0
        static void Main(string[] args)
        {
            //string sourceImg = @"D:\pictures\SquareBg1.png";
            //string destImg = @"D:\pictures\dest1.png";

            //ImageHandle.CombinImage(sourceImg,destImg);
            //ImageHandle.SquareImage(sourceImg, null);
            Sample sample = ImageHandle.CreateYuanXing();

            ImageHelp.CreateImage(sample, true);
        }
        public FileContentResult SecurityCode()
        {
            var imageHelp = new ImageHelp();
            var code      = imageHelp.CreateRandomCode(4).ToUpper();

            Session["LokFuCode"] = code;
            var image  = imageHelp.CreateImage(code);
            var buffer = image.GetBuffer();

            image.Close();
            return(File(buffer, "image/gif"));
        }
예제 #4
0
 /// <summary>
 /// 设置菜单的图标
 /// </summary>
 private void SetSubItemImage4Default(WinformMenu menuDefining, BarItem subItem)
 {
     if (menuDefining.DefaultEnable)
     {
         if (menuDefining.Icon != null)
         {
             if (menuDefining.Icon.Width >= 32)
             {
                 subItem.ImageOptions.LargeImage = menuDefining.Icon;
             }
             else
             {
                 subItem.ImageOptions.Image = menuDefining.Icon;
             }
         }
     }
     else
     {
         if (menuDefining.DisIcon != null)
         {
             if (menuDefining.DisIcon.Width >= 32)
             {
                 subItem.ImageOptions.LargeImage = menuDefining.DisIcon;
             }
             else
             {
                 subItem.ImageOptions.Image = menuDefining.DisIcon;
             }
         }
         else
         {
             if (menuDefining.Icon != null)
             {
                 if (menuDefining.Icon.Width >= 32)
                 {
                     subItem.ImageOptions.LargeImage = ImageHelp.ExColorDepth(menuDefining.Icon);
                 }
                 else
                 {
                     subItem.ImageOptions.Image = ImageHelp.ExColorDepth(menuDefining.Icon);
                 }
             }
         }
     }
 }
예제 #5
0
        public async void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args)
        {
            if ((args.ContinuationData["Operation"] as string) == "ImageWeibo" && args.Files != null && args.Files.Count > 0)
            {
                for (int i = 0; i < args.Files.Count; i++)
                {
                    ((DreamingViewModel)(DataContext)).ImagePathList.Add(args.Files[i].Path);


                    string path = await ImageHelp.GetImagePath(args.Files[i]);

                    Imagelist.Add(new DataHelp.Models.DreamingModel.imageModel {
                        i = path
                    });
                }
                listView.ItemsSource = Imagelist;
            }
            isPicure = false;
        }
예제 #6
0
        public async void HttpPost(string uid, string uimage, string name, string content, List <string> imagePsthList, string songPath, string date, int type)
        {
            NotifyControl notify = new NotifyControl();

            notify.Text = "亲,努力发送中...";
            notify.Show();
            HttpClient httpClient     = new HttpClient();
            uint       MaxImageWidth  = 480;
            uint       MaxImageHeight = 800;
            uint       width;
            uint       height;

            try
            {
                string posturi = Config.apiDreamingPublish;
                HttpMultipartFormDataContent fileContent = new HttpMultipartFormDataContent();
                if (imagePsthList.Count > 0)
                {
                    for (int i = 0; i < imagePsthList.Count; i++)
                    {
                        StorageFile inFile = await StorageFile.GetFileFromPathAsync(imagePsthList[i]);

                        var inStream = await inFile.OpenReadAsync();

                        InMemoryRandomAccessStream outStream = new InMemoryRandomAccessStream();
                        BitmapDecoder decoder = await ImageHelp.GetProperDecoder(inStream, inFile);

                        if (decoder == null)
                        {
                            return;
                        }


                        if (decoder.OrientedPixelWidth > MaxImageWidth && decoder.OrientedPixelHeight > MaxImageHeight)
                        {
                            width  = MaxImageWidth;
                            height = MaxImageHeight;
                        }
                        else
                        {
                            width  = decoder.OrientedPixelWidth;
                            height = decoder.OrientedPixelHeight;
                        }



                        PixelDataProvider provider = await decoder.GetPixelDataAsync();

                        byte[] data = provider.DetachPixelData(); //获取像素数据的字节数组


                        BitmapPropertySet propertySet  = new BitmapPropertySet();
                        BitmapTypedValue  qualityValue = new BitmapTypedValue(0.5, PropertyType.Single);
                        propertySet.Add("ImageQuality", qualityValue);


                        var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, outStream, propertySet);//建立编码器

                        encoder.SetPixelData(decoder.BitmapPixelFormat,
                                             decoder.BitmapAlphaMode,
                                             decoder.OrientedPixelWidth,
                                             decoder.OrientedPixelHeight,
                                             decoder.DpiX,
                                             decoder.DpiY,
                                             data
                                             );

                        encoder.BitmapTransform.ScaledWidth  = width;
                        encoder.BitmapTransform.ScaledHeight = height;
                        await encoder.FlushAsync();

                        HttpStreamContent streamContent1 = new HttpStreamContent(outStream);
                        fileContent.Add(streamContent1, "pic", inFile.Name);
                    }
                }


                if (songPath != null)
                {
                    StorageFile file1 = await StorageFile.GetFileFromPathAsync(songPath);

                    IRandomAccessStreamWithContentType stream1 = await file1.OpenReadAsync();

                    HttpStreamContent streamContent1 = new HttpStreamContent(stream1);
                    fileContent.Add(streamContent1, "song", file1.Name);
                }

                HttpStringContent stringContent = new HttpStringContent(content);
                HttpStringContent stringName    = new HttpStringContent(name);
                HttpStringContent stringUid     = new HttpStringContent(uid);
                HttpStringContent stringUimage  = new HttpStringContent(uimage);
                HttpStringContent stringTime    = new HttpStringContent(date);
                HttpStringContent stringType    = new HttpStringContent(type.ToString());


                fileContent.Add(stringContent, "content");
                fileContent.Add(stringUid, "phone");
                fileContent.Add(stringUimage, "uimage");

                fileContent.Add(stringName, "name");
                fileContent.Add(stringTime, "time");
                fileContent.Add(stringType, "type");

                HttpResponseMessage response = await httpClient.PostAsync(new Uri(posturi), fileContent);

                Init();
                notify.Hide();
                PostCommand.CanExecutes = true;
                NavigationHelp.NavigateTo(typeof(AllDreaming));
            }
            catch (Exception ex)
            {
                HelpMethods.Msg(ex.Message.ToString());
            }
        }
예제 #7
0
        public ActionResult Create2(FormCollection collection, string type)
        {
            Order order = new Order();

            order.SampleId  = int.Parse(collection["SampleId"]);
            order.TaobaoId  = collection["TaobaoId"];
            order.ImageUrl  = collection["ImageUrl"];
            order.MainText  = collection["MainText"];
            order.SmallText = collection["SmallText"];
            if (type == "提交订单")
            {
                try
                {
                    if (string.IsNullOrEmpty(order.ImageUrl))
                    {
                        throw new Exception("请先生成订单图片!");
                    }
                    order.SubmitTime  = DateTime.Now;
                    order.Status      = (int)EnumStatus.待审批;
                    order.SubmitTime  = DateTime.Now;
                    order.ProductTime = DateTime.MinValue;
                    order.AuditTime   = DateTime.MinValue;
                    order.DeleteTime  = DateTime.MinValue;
                    orderService.Save(order);

                    return(RedirectToAction("Result", "Front", new { message = "订单提交成功!" }));
                }
                catch (Exception ex)
                {
                    ViewBag.Message = ex.Message;
                    log.Error(ex);
                    return(View("Create2", order));
                }
            }
            else if (type == "CreateImage")
            {
                try
                {
                    var ifExist = orderService.CheckTaobaoIdExist(order.TaobaoId);
                    if (ifExist)
                    {
                        return(Json(new { status = "Fail", message = "该淘宝订单号已经生成订单!" }, JsonRequestBehavior.AllowGet));
                    }
                    order.Sample = sampleService.GetSample(order.SampleId, true);
                    if (order.MainText.Length != order.Sample.MainTextNumber)
                    {
                        return(Json(new { status = "Fail", message = "输入的文字数量不对!" }, JsonRequestBehavior.AllowGet));
                    }

                    for (int i = 0; i < order.Sample.MainTextNumber; i++)
                    {
                        order.Sample.MainText[i].Text = order.MainText[i].ToString();
                    }
                    if (order.Sample.IfHasSmallText)
                    {
                        if (string.IsNullOrEmpty(order.SmallText))
                        {
                            return(Json(new { status = "Fail", message = "请输入副文字!" }, JsonRequestBehavior.AllowGet));
                        }
                        else
                        {
                            if (order.SmallText.Length > 11)
                            {
                                return(Json(new { status = "Fail", message = "副文字不能超过11个字!" }, JsonRequestBehavior.AllowGet));
                            }

                            for (int i = 0; i < order.Sample.SmallTextNumber; i++)
                            {
                                order.Sample.SmallText[i].Text = order.SmallText[i].ToString();
                            }
                        }
                    }

                    string imageUrl = ImageHelp.CreateImage(order.Sample, false, order.TaobaoId);
                    var    result   = Json(imageUrl);
                    return(result);
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                    return(Json(new { status = "Fail", message = ex.Message }, JsonRequestBehavior.AllowGet));
                }
            }
            return(View(order));
        }
예제 #8
0
        public ActionResult Create(FormCollection collection, string type)
        {
            Order order = new Order();

            order.SampleId = int.Parse(collection["SampleId"]);
            order.TaobaoId = order.SampleId + "_" + DateTime.Now.Ticks;
            order.ImageUrl = collection["ImageUrl"];
            string mainText  = collection["MainText"] ?? "";
            string smallText = collection["SmallText"] ?? "";

            order.MainText  = mainText.Trim();
            order.SmallText = smallText.Trim();
            string    fontStr = collection["Font"];
            ImageFont font    = null;

            order.Sample = sampleService.GetSample(order.SampleId, true);
            if (fontStr != "" && fontStr != "0") //改了sample的字体
            {
                int fontId = int.Parse(fontStr);
                font                   = imageFontService.GetById(fontId);
                order.Font             = font.name;
                order.Sample.ImageFont = font;
            }
            else//沿用sample的字体
            {
                order.Font             = order.Sample.Font;
                font                   = imageFontService.GetByName(order.Sample.Font);
                order.Sample.ImageFont = font;
            }
            if (type == "提交订单")
            {
                try
                {
                    if (string.IsNullOrEmpty(order.ImageUrl))
                    {
                        throw new Exception("请先生成订单图片!");
                    }
                    order.SubmitTime  = DateTime.Now;
                    order.Status      = (int)EnumStatus.待审批;
                    order.SubmitTime  = DateTime.Now;
                    order.ProductTime = DateTime.MinValue;
                    order.AuditTime   = DateTime.MinValue;
                    order.DeleteTime  = DateTime.MinValue;

                    orderService.Save(order);
                    string logDetail = order.Sample.ImageType.ToString() + "-" + order.MainText;
                    var    logs      = new Logs {
                        Action = EnumAction.新建订单, Detail = logDetail, UserId = UserHelper.GetCurrentUser.Id, Time = DateTime.Now
                    };
                    logService.Insert(logs);
                    return(RedirectToAction("DownloadFile", new { imageURL = order.ImageUrl }));
                }
                catch (Exception ex)
                {
                    ViewBag.Message = ex.Message;
                    log.Error(ex);
                    return(View("Create", order.Sample));
                }
            }
            else if (type == "CreateImage")
            {
                try
                {
                    var ifExist = orderService.CheckTaobaoIdExist(order.TaobaoId);
                    if (ifExist)
                    {
                        return(Json(new { status = "Fail", message = "该淘宝订单号已经生成订单!" }, JsonRequestBehavior.AllowGet));
                    }
                    if (order.MainText.Length != order.Sample.MainTextNumber)
                    {
                        return(Json(new { status = "Fail", message = "输入的文字数量不对!" }, JsonRequestBehavior.AllowGet));
                    }

                    for (int i = 0; i < order.Sample.MainTextNumber; i++)
                    {
                        order.Sample.MainText[i].Text = order.MainText[i].ToString();
                    }
                    if (order.Sample.IfHasSmallText)
                    {
                        var smallTextArray = collection.AllKeys.Where(t => t.StartsWith("SmallText"));
                        foreach (var item in smallTextArray)
                        {
                            string indexSt = item.Substring(9, 1);
                            int    i       = Convert.ToInt32(indexSt);
                            string text    = collection["SmallText" + i].ToString();
                            if (text.Length > Constants.smallTextLimits)
                            {
                                return(Json(new { status = "Fail", message = "副文字不能超过11个字!" }, JsonRequestBehavior.AllowGet));
                            }
                            order.Sample.SmallText[i - 1].Text = text;
                        }
                    }

                    string imageUrl = ImageHelp.CreateImage(order.Sample, false, order.TaobaoId);

                    var logs = new Logs {
                        Action = EnumAction.创建订单图片, Detail = order.MainText, UserId = UserHelper.GetCurrentUser.Id, Time = DateTime.Now
                    };
                    logService.Insert(logs);

                    var result = Json(imageUrl);
                    return(result);
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                    return(Json(new { status = "Fail", message = ex.Message }, JsonRequestBehavior.AllowGet));
                }
            }
            return(View(order));
        }
예제 #9
0
        public ActionResult Update(FormCollection collection, string type)
        {
            try
            {
                #region init sample data
                int    sampleId = int.Parse(collection["ID"]);
                Sample sample   = sampleService.GetSample(sampleId, true);
                sample.IfHasBgImg = Convert.ToBoolean(int.Parse(collection["DDLIfHasBgImg"]));
                if (!sample.IfHasBgImg)
                {
                    sample.BgImage = "";
                }
                else
                {
                    sample.BgImage = collection["BgImage"];
                }
                if (type == "UploadFile")  //处理上传背景图片
                {
                    HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
                    if (files.Count == 0)
                    {
                        return(Json(new { status = "Fail", message = "请先上传文件!" }, JsonRequestBehavior.AllowGet));
                    }
                    try
                    {
                        var fullFileName = $"/UploadFiles/BgImages/{Guid.NewGuid() + "_" + files[0].FileName}";
                        if (!System.IO.File.Exists(fullFileName))
                        {
                            files[0].SaveAs(Server.MapPath(fullFileName));
                        }
                        sample.BgImage    = fullFileName;
                        sample.IfHasBgImg = true;
                        return(Json(fullFileName));
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex.Message);
                        return(Json(new { status = "Fail", message = ex.Message }, JsonRequestBehavior.AllowGet));
                    }
                }

                sample.Name     = collection["Name"];
                sample.ImageUrl = collection["ImageUrl"];

                List <ImageText> mainTexts = new List <ImageText>();
                ImageText        imageText = null;
                ImageFont        imageFont = null;
                int fontId = int.Parse(collection["Font"]);
                imageFont        = imageFontService.GetById(fontId);
                sample.Font      = imageFont.name;//第一个字的字体作为sample的字体,用于搜索过滤。
                sample.ImageFont = imageFont;
                string sizeStr = collection["Size"];
                sample = Utils.SetSize(sizeStr, sample);
                for (int i = 1; i < 5; i++)
                {
                    if (!string.IsNullOrEmpty(collection["Text" + i]))
                    {
                        imageText           = new ImageText();
                        imageText.Text      = collection["Text" + i];
                        imageText.Font      = imageFont.name;
                        imageText.imageFont = imageFont;
                        imageText.FontSize  = int.Parse(collection["FontSize" + i]);
                        imageText.PositionX = int.Parse(collection["PositionX" + i]);
                        imageText.PositionY = int.Parse(collection["PositionY" + i]);
                        imageText.Type      = (int)EnumTextType.MainText;
                        imageText.Order     = true;
                        mainTexts.Add(imageText);
                    }
                }
                sample.MainText       = mainTexts;
                sample.MainTextNumber = mainTexts.Count;
                // todo
                //if (!string.IsNullOrEmpty(collection["Text5"]))  //small text
                //{
                //    imageText = new ImageText();
                //    imageText.Text = collection["Text5"];
                //    imageText.Font = imageFont.name;
                //    imageText.imageFont = imageFont;
                //    imageText.FontSize = int.Parse(collection["FontSize5"]);
                //    imageText.PositionX = int.Parse(collection["PositionX5"]);
                //    imageText.PositionY = int.Parse(collection["PositionY5"]);
                //    imageText.Type = (int)EnumTextType.SmallText;
                //    imageText.Order = Convert.ToBoolean(int.Parse(collection["FontOrder"]));
                //    sample.IfHasSmallText = true;
                //    sample.SmallText = imageText;
                //}

                #endregion
                if (type == "保存")
                {
                    if (string.IsNullOrEmpty(sample.ImageUrl))
                    {
                        throw new Exception("请先生成样式图片!");
                    }
                    sampleService.Update(sample);
                    return(RedirectToAction("Index"));
                }
                else if (type == "CreateImage")
                {
                    try
                    {
                        InitData();
                        if (!CheckUpdateNameUnique(sample.Name, sample.Id))
                        {
                            return(Json(new { status = "Fail", message = "该名称已经存在,请使用唯一的名称!" }, JsonRequestBehavior.AllowGet));
                        }
                        string imageUrl = ImageHelp.CreateImage(sample, true, null);
                        return(Json(imageUrl));
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex.Message);
                        return(Json(new { status = "Fail", message = ex.Message }, JsonRequestBehavior.AllowGet));
                    }
                }
                return(View());
            }
            catch (Exception ex)
            {
                InitData();
                ViewBag.Message = ex.Message;
                log.Error(ex);
                return(View("Update"));
            }
        }
예제 #10
0
        public ActionResult Create(FormCollection collection, string type)
        {
            try
            {
                #region init sample data
                Sample sample = new Sample();
                sample.IfHasBgImg = Convert.ToBoolean(int.Parse(collection["IfHasBgImage"]));
                if (!sample.IfHasBgImg)
                {
                    sample.BgImage = "";
                }
                else
                {
                    sample.BgImage = collection["BgImage"];
                }
                if (type == "UploadFile")  //处理上传背景图片
                {
                    HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
                    if (files.Count == 0)
                    {
                        return(Json(new { status = "Fail", message = "请先上传文件!" }, JsonRequestBehavior.AllowGet));
                    }
                    try
                    {
                        var fullFileName = $"/UploadFiles/BgImages/{Guid.NewGuid() + "_" + files[0].FileName}";
                        if (!System.IO.File.Exists(fullFileName))
                        {
                            files[0].SaveAs(Server.MapPath(fullFileName));
                        }
                        sample.BgImage    = fullFileName;
                        sample.IfHasBgImg = true;
                        return(Json(fullFileName));
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex.Message);
                        return(Json(new { status = "Fail", message = ex.Message }, JsonRequestBehavior.AllowGet));
                    }
                }

                sample.Name      = collection["Name"];
                sample.ImageType = (EnumImageType)int.Parse(collection["ImageType"]);
                sample.Style     = (EnumImageStyle)int.Parse(collection["Style"]);
                sample.ImageUrl  = collection["ImageUrl"];
                string sizeStr = collection["Size"];
                sample = Utils.SetSize(sizeStr, sample);

                List <ImageText> mainTexts  = new List <ImageText>();
                List <ImageText> smallTexts = new List <ImageText>();
                ImageText        imageText  = null;
                ImageFont        imageFont  = null;
                int fontId = int.Parse(collection["Font"]);
                imageFont        = imageFontService.GetById(fontId);
                sample.Font      = imageFont.name;//第一个字的字体作为sample的字体,用于搜索过滤。
                sample.ImageFont = imageFont;

                var mainTextArray = collection.AllKeys.Where(t => t.StartsWith("Text"));  //把所有Text开头的拿出来,遍历。
                foreach (string str in mainTextArray)
                {
                    int    i    = Convert.ToInt32(str.Substring(4, 1)); //Text1 取后面的数字
                    string text = collection["Text" + i];
                    if (!string.IsNullOrEmpty(text))
                    {
                        imageText           = new ImageText();
                        imageText.Text      = text;
                        imageText.Font      = imageFont.name;
                        imageText.imageFont = imageFont;
                        imageText.FontSize  = int.Parse(collection["FontSize" + i]);
                        imageText.PositionX = int.Parse(collection["PositionX" + i]);
                        imageText.PositionY = int.Parse(collection["PositionY" + i]);
                        imageText.Type      = (int)EnumTextType.MainText;
                        imageText.Order     = true;
                        mainTexts.Add(imageText);
                    }
                }
                sample.MainText       = mainTexts;
                sample.MainTextNumber = mainTexts.Count;
                var smallTextArray = collection.AllKeys.Where(t => t.StartsWith("SmallText"));  //把所有SmallText开头的拿出来,遍历。
                foreach (string str in smallTextArray)
                {
                    int    i    = Convert.ToInt32(str.Substring(9, 1)); //SmallText1 取后面的数字
                    string text = collection["SmallText" + i];
                    if (!string.IsNullOrEmpty(text))                    //small text
                    {
                        imageText           = new ImageText();
                        imageText.Text      = text;
                        imageText.Font      = imageFont.name;
                        imageText.imageFont = imageFont;
                        imageText.FontSize  = int.Parse(collection["SmallFontSize" + i]);
                        imageText.PositionX = int.Parse(collection["SmallPositionX" + i]);
                        imageText.PositionY = int.Parse(collection["SmallPositionY" + i]);
                        imageText.Type      = (int)EnumTextType.SmallText;
                        imageText.Order     = Convert.ToBoolean(int.Parse(collection["SmallFontOrder" + i]));
                        smallTexts.Add(imageText);
                    }
                }
                sample.SmallText = smallTexts;
                if (smallTexts.Count > 0)
                {
                    sample.IfHasSmallText  = true;
                    sample.SmallTextNumber = smallTexts.Count;
                }

                #endregion
                if (type == "保存")
                {
                    if (string.IsNullOrEmpty(sample.ImageUrl))
                    {
                        throw new Exception("请先生成样式图片!");
                    }
                    sampleService.Insert(sample);
                    var logs = new Logs {
                        Action = EnumAction.新建预设样式, Detail = sample.Name, UserId = UserHelper.GetCurrentUser.Id, Time = DateTime.Now
                    };
                    logService.Insert(logs);
                    return(RedirectToAction("Index"));
                }
                else if (type == "CreateImage")
                {
                    try
                    {
                        InitData();
                        if (!CheckNameUnique(sample.Name))
                        {
                            return(Json(new { status = "Fail", message = "该名称已经存在,请使用唯一的名称!" }, JsonRequestBehavior.AllowGet));
                        }
                        string imageUrl = ImageHelp.CreateImage(sample, true, null);
                        return(Json(imageUrl));
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex.Message);
                        return(Json(new { status = "Fail", message = ex.Message }, JsonRequestBehavior.AllowGet));
                    }
                }
                return(View());
            }
            catch (Exception ex)
            {
                InitData();
                ViewBag.Message = ex.Message;
                log.Error(ex);
                return(View("Create"));
            }
        }