Exemplo n.º 1
0
 private void HanlderSetTextWater(string fullPath, UploadImageInfo uploadImageInfo)
 {
     if (uploadImageInfo.IsSetPicWater)
     {
         ImageHelper.AttachText(SetWordWater, fullPath);
     }
 }
Exemplo n.º 2
0
 private void HanlderSetPicWater(string fullPath, UploadImageInfo uploadImageInfo)
 {
     if (uploadImageInfo.IsSetPicWater)
     {
         ImageHelper.AttachPng(SetPicWater, fullPath, SetPositionWater);
     }
 }
Exemplo n.º 3
0
 public static UploadImageInfoDto ToDto(this UploadImageInfo obj)
 {
     return(new()
     {
         UploadId = obj.UploadId,
         Url = obj.Url
     });
 }
Exemplo n.º 4
0
        public static async Task <string> ShutterCounterAsync(UploadImageInfo uploadImageInfo)
        {
            HttpClient          httpClient         = new HttpClient();
            var                 content            = new MultipartFormDataContent();
            var                 contentByteContent = new ByteArrayContent(uploadImageInfo.ContentByte);
            HttpResponseMessage response           = new HttpResponseMessage();

            httpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0");
            httpClient.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
            httpClient.DefaultRequestHeaders.Add("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2");
            httpClient.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate");
            httpClient.DefaultRequestHeaders.Add("Referer", "http://tools.science.si/index.php");
            httpClient.DefaultRequestHeaders.Add("Upgrade-Insecure-Requests", "1");

            contentByteContent.Headers.Add("Content-Type", "image/jpeg");
            contentByteContent.Headers.ContentDisposition          = new ContentDispositionHeaderValue("form-data");
            contentByteContent.Headers.ContentDisposition.FileName = "\"" + uploadImageInfo.Name + "\"";
            contentByteContent.Headers.ContentDisposition.Name     = "\"filet\"";

            content.Add(new StringContent("ul"), "nacin");
            content.Add(new StringContent(""), "povezava");
            content.Add(contentByteContent, "imagefile");

            try
            {
                response = await httpClient.PostAsync(new Uri("http://tools.science.si/index.php", UriKind.Absolute), content);

                if (response.IsSuccessStatusCode)
                {
                    Stream stream = await response.Content.ReadAsStreamAsync();

                    string result = GZipDecom.GZipDecompress(stream);

                    if (result.Contains("sorry"))
                    {
                        return("无法识别");
                    }
                    else
                    {
                        string s = result.Split(":")[3].Split("<")[0];
                        string f = result.Split(":")[2].Split("file")[1];
                        string m = result.Split(":")[1].Split("<")[0];
                        return("根据文件" + f + "检测到机器" + m + "已使用快门" + s + "次。");
                    }
                }
                else
                {
                    return("传输错误");
                }
            }
            catch
            {
                return("传输错误");
            }
        }
Exemplo n.º 5
0
        private OperatedResult <UploadImageInfo> GetUploadImageInfo(HttpPostedFile postedFile, string savePath)
        {
            CheckResult _checkedPostFileResult = CheckedPostFile(postedFile);

            if (!_checkedPostFileResult.State)
            {
                return(OperatedResult <UploadImageInfo> .Fail(_checkedPostFileResult.Message));
            }

            int    _randomNumber  = RandomHelper.NextNumber(1000, 9999);
            string _fileName      = DateTime.Now.FormatDate(12) + _randomNumber,
                   _fileEx        = Path.GetExtension(postedFile.FileName);
            double      _fileSize = postedFile.ContentLength / 1024.0 / 1024.0;
            CheckResult _checkedUploadImageResult = CheckedUploadImageParamter(_fileEx, _fileSize);

            if (!_checkedUploadImageResult.State)
            {
                return(OperatedResult <UploadImageInfo> .Fail(_checkedUploadImageResult.Message));
            }

            UploadImageInfo _uploadImageInfo = new UploadImageInfo();

            _uploadImageInfo.FileName       = _fileName + _fileEx;
            _uploadImageInfo.FilePath       = savePath.Trim('\\') + "\\" + _uploadImageInfo.FileName;
            _uploadImageInfo.WebPath        = "/" + _uploadImageInfo.FilePath.Replace(HttpContext.Current.Server.MapPath("~/"), "").Replace("\\", "/");
            _uploadImageInfo.Size           = _fileSize;
            _uploadImageInfo.FileEx         = _fileEx;
            _uploadImageInfo.IsSetPicWater  = !string.IsNullOrEmpty(SetPicWater);
            _uploadImageInfo.IsSetWordWater = !string.IsNullOrEmpty(SetWordWater);
            BitmapInfo _iamgeInfo = ImageHelper.GetBitmapInfo(postedFile.FileName);

            _uploadImageInfo.SourceWidth       = _iamgeInfo.Width;
            _uploadImageInfo.SourceHeight      = _iamgeInfo.Height;
            _uploadImageInfo.IsCreateThumbnail = SetSmallImgWidth.Length != 0;
            _uploadImageInfo.ThumbnailHeight   = SetSmallImgHeight;
            _uploadImageInfo.ThumbnailWidth    = SetSmallImgWidth;

            if (_uploadImageInfo.IsCreateThumbnail && SetSmallImgHeight.Length != SetSmallImgHeight.Length)
            {
                return(OperatedResult <UploadImageInfo> .Fail(GetCodeMessage(6)));
            }

            FileHelper.CreateDirectory(savePath);
            postedFile.SaveAs(_uploadImageInfo.FilePath);
            return(OperatedResult <UploadImageInfo> .Success(_uploadImageInfo));
        }
Exemplo n.º 6
0
        public async Task StoreFriendLogoAsync(string friendId, UploadImageInfo imageInfo, Stream imageStream)
        {
            var friend = await _friendProvider.GetFriendOrDefaultAsync(friendId).ConfigureAwait(false);

            var imageId = await SaveImageDataAsync(imageInfo, imageStream);

            if (imageInfo.ImageSize == ImageSize.Full)
            {
                friend.LogoId = imageId;
            }
            else
            {
                friend.SmallLogoId = imageId;
            }

            await _friendProvider.SaveFriendAsync(friend);

            await _unitOfWork.SaveChangesAsync();
        }
Exemplo n.º 7
0
        public async Task StoreSpeakerAvatarAsync(string speakerId, UploadImageInfo imageInfo, Stream imageStream)
        {
            var speaker = await _speakerProvider.GetSpeakerOrDefaultAsync(speakerId).ConfigureAwait(false);

            var imageId = await SaveImageDataAsync(imageInfo, imageStream);

            if (imageInfo.ImageSize == ImageSize.Full)
            {
                speaker.AvatarId = imageId;
            }
            else
            {
                speaker.AvatarSmallId = imageId;
            }

            await _speakerProvider.SaveSpeakerAsync(speaker);

            await _unitOfWork.SaveChangesAsync();
        }
Exemplo n.º 8
0
        private async Task StoreImageAsync(ImageSize imageSize, IFormFile formFile, Func <UploadImageInfo, Stream, Task> saveImageAsync)
        {
            if (formFile == null || formFile.Length <= 0)
            {
                throw new ArgumentException("Can't read the file", nameof(formFile));
            }

            if (formFile.Length > _settings.AvatarMaxSize)
            {
                throw new ArgumentOutOfRangeException(nameof(formFile),
                                                      $"File size must be lower than {_settings.AvatarMaxSize.ToString()}");
            }

            using (var stream = formFile.OpenReadStream())
            {
                var imageInfo = new UploadImageInfo
                {
                    ImageSize = imageSize,
                    MimeType  = formFile.ContentType
                };

                await saveImageAsync(imageInfo, stream);
            }
        }
Exemplo n.º 9
0
        private async Task <int> SaveImageDataAsync(UploadImageInfo info, Stream imageStream)
        {
            using (var memory = new MemoryStream())
            {
                await imageStream.CopyToAsync(memory);

                memory.Position = 0;

                var bytes = memory.ToArray();

                var image = Image.Load(bytes);

                var imageData = await _imageProvider.SaveImageAsync(new ImageData
                {
                    Data     = bytes,
                    Height   = image.Height,
                    Width    = image.Width,
                    MimeType = info.MimeType,
                    IsSmall  = info.ImageSize == ImageSize.Small
                });

                return(imageData.Id);
            }
        }
Exemplo n.º 10
0
        public static Dictionary <string, string> WXUploadFile(string ServerID, UploadImageInfo model)
        {
            //string gps= map_tx2bd(double.Parse(model.GPSLatitude), double.Parse(model.GPSLongitude));

            string filePath    = System.Configuration.ConfigurationManager.AppSettings[BaseDictType.TempFileUploadPath];
            var    filename    = Util.RPCNow.Ticks.ToString() + Util.RPCNow.Millisecond + ".jpg";
            var    saveURl     = System.Web.HttpContext.Current.Server.MapPath(filePath) + filename;
            var    accessToken = WeixinCache.GetCorpAccessToken();

            using (MemoryStream stream = new MemoryStream())
            {
                MediaApi.Get(accessToken, ServerID, stream);

                if (!System.IO.Directory.Exists(saveURl))
                {
                    System.IO.Directory.CreateDirectory(saveURl.Replace(filename, ""));
                }
                using (var fs = new FileStream(saveURl, FileMode.CreateNew))
                {
                    stream.Seek(0, SeekOrigin.Begin);
                    stream.CopyTo(fs);
                    fs.Flush();
                }
            }

            Dictionary <string, string> data = new Dictionary <string, string>();

            MemoryStream ms = new System.IO.MemoryStream(System.IO.File.ReadAllBytes(saveURl));

            try
            {
                string strDescription = model.DateTimeOriginal + "\r\n";
                strDescription += model.StoreAddr + "\r\n";                 // + " 精度(" + model.SignPoint + ")" ;
                strDescription += model.StoreCode + " " + model.StoreName + "\r\n";
                strDescription += model.EmpCode + " " + model.EmpName + "(" + model.EmpDuty + ")\r\n";

                System.Drawing.Image image = System.Drawing.Image.FromStream(ms);
                Graphics             g     = Graphics.FromImage(image);
                //Brush drawBrush = new SolidBrush(System.Drawing.Color.FromArgb(((System.Byte)(222)), ((System.Byte)(243)), ((System.Byte)(255)))); //自定义字体颜色
                Font       font    = new Font("宋体", 10);
                SizeF      sizeF   = g.MeasureString(" " + strDescription + " ", font);
                Color      Mycolor = System.Drawing.Color.FromArgb(0, 0, 0, 0);           //说明:1-(128/255)=1-0.5=0.5 透明度为0.5,即50%
                SolidBrush sb1     = new System.Drawing.SolidBrush(Mycolor);
                g.FillRectangle(sb1, new RectangleF(new PointF(0, image.Height - 100), sizeF));
                //FillRoundRectangle(g, sb1, new Rectangle(15, 20, (int)sizeF.Width+20, (int)sizeF.Height), 8);
                //DrawRoundRectangle(g, Pens.Transparent, new Rectangle(15, 20, (int)sizeF.Width +20, (int)sizeF.Height), 8);
                g.DrawString(strDescription, new Font("宋体", 10), Brushes.White, new PointF(2, image.Height - 94));

                System.IO.File.Delete(saveURl);
                image.Save(saveURl);

                var url = filePath + filename;

                data.Add("status", "1");
                data.Add("content", "上传成功");
                data.Add("url", url);
                data.Add("filename", filename);
            }
            catch (Exception ex)
            {
                data.Add("status", "0");
                data.Add("content", "上传失败");
                data.Add("url", "");
                data.Add("filename", "");
            }
            finally
            {
                ms.Close();
            }

            //string returnstring=PostApply(hpf, DateTimeOriginal, GPSLatitude, GPSLongitude);


            return(data);
        }
Exemplo n.º 11
0
        public static Dictionary <string, string> UploadFile(string hpf, UploadImageInfo model)
        {
            string filePath = System.Configuration.ConfigurationManager.AppSettings[BaseDictType.TempFileUploadPath];

            Dictionary <string, string> data = new Dictionary <string, string>();

            string saveUrl = System.Web.HttpContext.Current.Server.MapPath(filePath);

            if (!System.IO.Directory.Exists(saveUrl))
            {
                System.IO.Directory.CreateDirectory(saveUrl);
            }

            //将文件流写到byte数组中
            byte[]       arr = Convert.FromBase64String(hpf);
            MemoryStream ms  = new MemoryStream(arr);
            Bitmap       bmp = new Bitmap(ms);

            var filename = Util.RPCNow.Ticks.ToString() + Util.RPCNow.Millisecond + ".jpg";

            try
            {
                var saveurl = saveUrl + filename;
                bmp.Save(saveurl, System.Drawing.Imaging.ImageFormat.Jpeg);
                //bmp.Save(txtFileName + ".bmp", ImageFormat.Bmp);
                //bmp.Save(txtFileName + ".gif", ImageFormat.Gif);
                //bmp.Save(txtFileName + ".png", ImageFormat.Png);
                bmp.Dispose();
                ms.Close();

                string strDescription = model.DateTimeOriginal + "\r\n";
                strDescription += model.StoreAddr + "\r\n";                 // + " 精度(" + model.SignPoint + ")";
                strDescription += model.StoreCode + " " + model.StoreName + "\r\n";
                strDescription += model.EmpCode + " " + model.EmpName + "(" + model.EmpDuty + ")\r\n";
                //strDescription += "纬度:" + GetGPSLatitude(GPSLatitude) + "\r\n";
                //strDescription += "经度:" + GetGPSLatitude(GPSLongitude) + "\r\n";
                //strDescription += GetDistance(GPSLatitude, GPSLongitude, storeGPSLat, storeGPSLng) ;
                //strDescription += "拍摄地址:" + GetAddrName(GetGPSLatitude(model.GPSLatitude) + "," + GetGPSLatitude(model.GPSLongitude));

                ms = new System.IO.MemoryStream(System.IO.File.ReadAllBytes(saveurl));
                System.Drawing.Image image = System.Drawing.Image.FromStream(ms);
                Graphics             g     = Graphics.FromImage(image);
                //Brush drawBrush = new SolidBrush(System.Drawing.Color.FromArgb(((System.Byte)(222)), ((System.Byte)(243)), ((System.Byte)(255)))); //自定义字体颜色
                Font       font    = new Font("宋体", 10);
                SizeF      sizeF   = g.MeasureString(" " + strDescription + " ", font);
                Color      Mycolor = System.Drawing.Color.FromArgb(0, 0, 0, 0);           //说明:1-(128/255)=1-0.5=0.5 透明度为0.5,即50%
                SolidBrush sb1     = new System.Drawing.SolidBrush(Mycolor);
                g.FillRectangle(sb1, new RectangleF(new PointF(0, image.Height - 100), sizeF));
                //FillRoundRectangle(g, sb1, new Rectangle(15, 20, (int)sizeF.Width+20, (int)sizeF.Height), 8);
                //DrawRoundRectangle(g, Pens.Transparent, new Rectangle(15, 20, (int)sizeF.Width +20, (int)sizeF.Height), 8);
                g.DrawString(strDescription, new Font("宋体", 10), Brushes.White, new PointF(2, image.Height - 94));

                System.IO.File.Delete(saveurl);
                image.Save(saveurl);

                var url = filePath + filename;

                data.Add("status", "1");
                data.Add("content", "上传成功");
                data.Add("url", url);
                data.Add("filename", filename);
            }
            catch (Exception ex)
            {
                data.Add("status", "0");
                data.Add("content", "上传失败");
                data.Add("url", "");
                data.Add("filename", "");
            }
            finally
            {
                bmp.Dispose();
                ms.Close();
            }

            //string returnstring=PostApply(hpf, DateTimeOriginal, GPSLatitude, GPSLongitude);


            return(data);
        }
Exemplo n.º 12
0
        private static async Task <PostStatus> UploadImage(WebClient wc, Image image, string booru, string apiKey)
        {
            // Set required headers
            wc.Headers["User-Agent"]   = UserAgent;
            wc.Headers["Content-Type"] = "application/json";

            string uploadUrl = GetUploadImageUrl(booru, apiKey);

            // Format the tags into a comma-separated string
            string tagString = string.Join(", ", image.tags);

            // Create upload json
            UploadImageInfo uploadImage = new UploadImageInfo
            {
                description = image.description,
                tag_input   = tagString,
                source_url  = image.source_url
            };

            UploadImageBody uploadImageBody = new UploadImageBody
            {
                image = uploadImage,
                url   = image.view_url
            };
            string uploadImageString = JsonConvert.SerializeObject(uploadImageBody);

            try {
                await wc.UploadDataTaskAsync(uploadUrl, Encoding.UTF8.GetBytes(uploadImageString));

                return(PostStatus.Success);
            }
            catch (WebException ex) {
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    HttpWebResponse response = ex.Response as HttpWebResponse;
                    if (response != null)
                    {
                        if (response.StatusCode == HttpStatusCode.BadRequest)    // Already uploaded (duplicate hash)
                        {
                            Console.WriteLine("Image has already been uploaded");
                            return(PostStatus.Duplicate);
                        }
                        else
                        {
                            // Other http status code
                            Console.WriteLine($"Error uploading image ({response.StatusCode})");
                        }
                    }
                    else
                    {
                        // no http status code available
                        Console.WriteLine("Error uploading image (Unknown error)");
                    }
                }
                else
                {
                    // no http status code available
                    Console.WriteLine("Error uploading image (Unknown error)");
                }
            }

            return(PostStatus.Failure);
        }
Exemplo n.º 13
0
        private void HanlderThumbnailImage(string fullPath, string savePath, string fileName, string fileEx, int sourceWidth, int sourceHeight, UploadImageInfo uploadImageInfo)
        {
            if (uploadImageInfo.IsCreateThumbnail)
            {
                int[] _thumbnailWidthRule = uploadImageInfo.ThumbnailWidth,
                _thumbnailHeightRule = uploadImageInfo.ThumbnailHeight;

                for (int i = 0; i < _thumbnailWidthRule.Length; i++)
                {
                    if (_thumbnailWidthRule[i] <= 0 || _thumbnailHeightRule[i] <= 0)
                    {
                        continue;
                    }

                    string _descFile = savePath.TrimEnd('\\') + '\\' + fileName + "_" + i.ToString() + fileEx;

                    //判断图片高宽是否大于生成高宽。否则用原图
                    if (sourceWidth > Convert.ToInt32(_thumbnailWidthRule[i]))
                    {
                        if (SetCutImage)
                        {
                            ImageHelper.CreateSmallPhoto(fullPath, _thumbnailWidthRule[i], _thumbnailHeightRule[i], _descFile);
                        }

                        else
                        {
                            ImageHelper.CreateSmallPhoto(fullPath, _thumbnailWidthRule[i], _thumbnailHeightRule[i], _descFile, CutType.CutNo);
                        }
                    }

                    else
                    {
                        if (SetCutImage)
                        {
                            ImageHelper.CreateSmallPhoto(fullPath, sourceWidth, sourceHeight, _descFile);
                        }

                        else
                        {
                            ImageHelper.CreateSmallPhoto(fullPath, sourceWidth, sourceHeight, _descFile, CutType.CutNo);
                        }
                    }
                }
            }
        }