ASP.NET网页 - 使用WebImage来调整和保存照片 [英] ASP.NET Web Pages - Using WebImage to resize and save a photo

查看:141
本文介绍了ASP.NET网页 - 使用WebImage来调整和保存照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP.NET网页创建一个形式,我可以选择一个图像。我想然后将图像调整成各种不同的大小,这样我可以在我的网站上显示它们。

I'm using ASP.NET Web Pages to create a form in which I can select an image. I want to then resize the image into various different sizes so that I can display them on my website.

这是工作的小图像(文件大小),但我想调整画面从我的数码单反相机,它们可以为每张JPEG 14MB一样大。我得到了以下错误...

This is working for smaller images (in filesize), but the images I want to resize are from my digital SLR and they can be as large as 14MB per jpeg. I got the following error...

Maximum request length exceeded.

我添加了一个的web.config 通过以下code:

<?xml version="1.0"?>

<configuration>

    <system.web>
        <compilation debug="false" targetFramework="4.0" />
        <httpRuntime maxRequestLength="20480" />  
    </system.web>

</configuration>

我不再得到的错误,但它实际上并没有做任何事情。它仍然有效使用较小的图像。

I no longer get the error, but it doesn't actually do anything. It still works with smaller images.

我在这里使用教程:的http://www.asp.net/web-pages/tutorials/files,-images,-and-media/9-working-with-images

我的code是如下:

@{  WebImage photo = null;
    var newFileName = "";
    var imagePath = "";
    var imageThumbPath  = "";

    if(IsPost){
        photo = WebImage.GetImageFromRequest();
        if(photo != null){
            newFileName = "Original_" + Path.GetFileName(photo.FileName);
            imagePath = @"images\" + newFileName;
            photo.Save(@"~\" + imagePath);

            newFileName = "Thumbnail_" + Path.GetFileName(photo.FileName);
            imagePath = @"images\" + newFileName;
            photo.Resize(width: 60, height: 60, preserveAspectRatio: true, preventEnlarge: true);
            photo.Save(@"~\" + imagePath);        
        }
    }
}

<!DOCTYPE html>

<html>
<head>
   <title>Resizing Image</title>
</head>

<body>

    <h1>Thumbnail Image</h1>
    <form action="" method="post" enctype="multipart/form-data">
        <fieldset>
            <legend> Creating Thumbnail Image </legend>

            <label for="Image">Image</label>
            <input type="file" name="Image" />
            <br/>
            <input type="submit" value="Submit" />
        </fieldset>
    </form>

</body>
</html>

为什么它不适合较大的图像工作的任何想法。任何帮助AP preciated!

Any ideas why it's not working for larger images. Any help appreciated!

推荐答案

微软的WebImage类的真正确实的差。在第一两三页读取源和点状出血〜10关键错误后,我放弃了它。这不是服务器安全的。

Microsoft's WebImage class is really, really poor. After reading the source and spotting ~10 critical bugs in the first two or three pages, I gave up on it. It's not server-safe.

imageresizing.net库的被设计为在服务器上运行,并管理存储器好得多。对于单反相机的照片,你仍然需要的RAM约100-200MB至DECOM preSS一个单一的形象,但如果你有,它应该得到这份工作相当可靠地完成。它已经与千兆像素大小的图像成功地使用,所以你的单反会的容易的,只要你有一个RAM茶匙。

My imageresizing.net library is designed to run on the server, and manages memory much better. For SLR photos you will still need about 100-200MB of RAM to decompress a single image, but if you have that, it should get the job done quite reliably. It's been used successfully with gigapixel sized images, so your SLR will be easy as long as you have a teaspoon of RAM.

这里有一个如何上传,调整大小和保存与图书馆的例子。使用上传的文件名是一个非常大的漏洞 - 一个GUID是一个更安全的选择。

Here's an example of how to upload, resize, and save with the library. Using the uploaded file name is a really big vulnerability - a GUID is a much safer choice.

然而,由于该库的非常的速度快,旨在支持单一来源的影像,你可以考虑只保存原始和动态生成缩略图。该 DiskCache插件将他们缓存到磁盘静态文件,由IIS服务 - 它提供了出色的性能。

However, since the library is extremely fast, and is designed to support single-source imaging, you might consider just saving the original, and generating the thumbnails dynamically. The DiskCache plugin will cache them to disk as static files, served by IIS - it provides great performance.

这篇关于ASP.NET网页 - 使用WebImage来调整和保存照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆