コード例 #1
0
        static public string ResizeImageH(string image, int maxHeight, string destinationPath)
        {
            if (string.IsNullOrEmpty(image))
            {
                return(image);
            }
            var result = string.Empty;

            byte[] rebin        = Convert.FromBase64String(image);
            var    tempFileName = Path.Combine(Path.GetDirectoryName(destinationPath), $"{Guid.NewGuid()}.jpg");

            using (FileStream fs2 = new FileStream(tempFileName, FileMode.Create))
                using (BinaryWriter bw = new BinaryWriter(fs2))
                    bw.Write(rebin);
            using (var img = Bitmap.FromFile(tempFileName))
            {
                using (var bitmap = new Bitmap(img))
                {
                    var imgPath = !string.IsNullOrEmpty(destinationPath) ?
                                  destinationPath : Path.ChangeExtension(tempFileName, ".jpg");
                    ResizeImage(bitmap, 9999, maxHeight, 100, imgPath);
                    result = BinaryHelper.FromImageToString(imgPath);
                }
            }
            File.Delete(tempFileName);
            File.Delete(Path.ChangeExtension(tempFileName, ".jpg"));
            return(result);
        }
コード例 #2
0
 private void Resize(string fullPath, ResizeRule rule)
 {
     if (rule.Width.HasValue && !rule.Height.HasValue)
     {
         var binary     = BinaryHelper.FromImageToString(fullPath);
         var outputPath = Path.Combine(rule.OutputPath, Path.GetFileName(fullPath));
         ImageHelper.ResizeImageW(binary, rule.Width.Value, outputPath);
     }
     else if (rule.Height.HasValue && !rule.Width.HasValue)
     {
         var binary     = BinaryHelper.FromImageToString(fullPath);
         var outputPath = Path.Combine(rule.OutputPath, Path.GetFileName(fullPath));
         ImageHelper.ResizeImageH(binary, rule.Height.Value, outputPath);
     }
     else
     {
         var binary     = BinaryHelper.FromImageToString(fullPath);
         var outputPath = Path.Combine(rule.OutputPath, Path.GetFileName(fullPath));
         ImageHelper.ResizeImage(binary, rule.Width.Value, rule.Height.Value, outputPath);
     }
 }
コード例 #3
0
        static public string ResizeImage(string image, int maxWidth, int maxHeight, string destinationPath)
        {
            byte[] rebin        = Convert.FromBase64String(image);
            var    tempFileName = Path.Combine(Path.GetDirectoryName(destinationPath), $"{Guid.NewGuid()}.jpg");

            using (FileStream fs2 = new FileStream(tempFileName, FileMode.Create))
                using (BinaryWriter bw = new BinaryWriter(fs2))
                    bw.Write(rebin);
            using (var img = Bitmap.FromFile(tempFileName))
            {
                using (var bitmap = new Bitmap(img))
                {
                    ResizeImage(bitmap, maxWidth, maxHeight, 100, destinationPath);
                }
            }
            if (File.Exists(tempFileName))
            {
                File.Delete(tempFileName);
            }
            return(BinaryHelper.FromImageToString(destinationPath));
        }