0
public static BinaryToImage(System.Data.Linq.Binary binaryData)
{
    if (binaryData == null) {
    return null;
    }
    byte[] buffer = binaryData.ToArray();
    System.Drawing.Image newImage = default(System.Drawing.Image);
    MemoryStream memStream = new MemoryStream();
    memStream.Write(buffer, 0, buffer.Length);
    using (MemoryStream strefgham = new MemoryStream(buffer)) {
       newImage = System.Drawing.Image.FromStream(strefgham);
       return newImage;
    }
}
public static double GetPercent(double width,double height,int originalWidth,int originalHeight)
 {
    if (width <= originalWidth && height <= originalHeight) {
    return 1.0;
    } else 
        {
    double wid = (originalWidth / width);
    double hei = (originalHeight / height);
    return (wid < hei) ? wid : hei;
   }
}


   System.Drawing.Image newImage = default(System.Drawing.Image);
   newImage = BinaryToImage(VarBinaryName.ToArray());
   double perc = GetPercent(newImage.Width, newImage.Height, 300, 300);
   double newWidth = newImage.Width * perc;
   double newHeight = newImage.Height * perc;
   int disWeight = Convert.ToInt32(newWidth);
   int disHeight = Convert.ToInt32(newHeight);

到目前为止,我能够将 varbinary(max) 转换为图像,并调整其大小。但无法将其保存在文件夹中。这与位图有关吗?有什么建议么?

4

1 回答 1

0

嘿添加此行以将您的图像保存在文件夹中

if (!Directory.Exists("D:\Test"))
        {
            Directory.CreateDirectory("D:\Test");
        }
newImage.Save(@"D:\Test\New.jpg", origImage.RawFormat);
于 2013-07-22T10:30:11.497 回答