【问题标题】:Create asp.net Image object from external image url从外部图像 url 创建 asp.net Image 对象
【发布时间】:2011-03-08 20:08:43
【问题描述】:

我想在服务器端裁剪图像(我使用的是“JCrop”和“ASP.NET 3.5”)。 有一种情况,用户可以将外部站点的图像添加到文章中。我想要 使用户能够从该图像创建缩略图并将结果存储在服务器上。 在这种情况下,代码类似于

string originalFile = Server.MapPath(this.srcImage.ImageUrl);
using (Image img = Image.FromFile(originalFile))
{
    using (System.Drawing.Bitmap _bitmap = new System.Drawing.Bitmap(w, h))
    {
        _bitmap.SetResolution(img.HorizontalResolution, img.VerticalResolution);
        ......
        [Please see code here][1] will not work as the image URL is external and not a file on the server's file system.

谁能告诉我如何从给定的外部图像 URL 字符串创建 System.Drawing.Image 对象

【问题讨论】:

    标签: asp.net image url image-manipulation


    【解决方案1】:

    从 Web 加载图像,将数据放入 MemoryStream(示例见此处:http://www.vcskicks.com/image-from-url.php

    然后使用 FromStream() 方法:

    http://msdn.microsoft.com/it-it/library/93z9ee4x(v=VS.80).aspx

    【讨论】:

      猜你喜欢
      • 2021-03-15
      • 1970-01-01
      • 2021-04-09
      • 2012-01-09
      • 2013-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多