The correct way to dynamically create images in an ASP.NET C # web application?

I'm new to ASP.NET, but I got quite a few WinForms applications in C #, where I used the namespace extensively System.Drawing.Bitmapwithout much trouble.

Today I decided to write some code to dynamically create some PNGs on the fly in my Page_Load event, and everything works fine. But I notice this scary looking warning on the Microsoft Office website. What is the reason for this?

I do not know about other methods of image processing in .Net, besides using System.Drawing.Bitmap... I am puzzled: (

+3
source share
4

, Windows (SCM) ​​( MS) (, ASP.NET), , this, , GDI + DLL- Windows. , Microsoft, , oles , , - = .

, .

ASP.NET, , , , use() {}. 99,9% (0,1 , :)

+2

Page_Load, , ASP.NET. , , ..

, HttpHandler ( Bitmap ). IHttpHandler, 2 , . - :

<%@ WebHandler Language="C#" Class="ImageHandler" %>
using System;
using System.IO;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;

public class ImageHandler : IHttpHandler
{
    public void ProcessRequest (HttpContext context)
    {   
        Bitmap output = new Bitmap(path);

        // Do lots of fun stuff here related to image
        // manipulation and/or generation

        ...

        context.Response.ContentType = ResponseType("Image/png");

        // Send image to the browser
        image.Save(context.Response.OutputStream, ImageType(path));

        // Be careful to clean up; you could put this inside a 'using' block    
        image.Dispose();
    }

    public bool IsReusable
    {
        get { return true; }
    }
}

: ... , .

HttpHandler, 50% awesome. , , , ... ; -)

+3

, , " ", - ".
, .

0

GDI + ASP.NET, , (100 000 ) , , , , .

, , , ASP.NET MSMQ. , - .

, Image.FromFile(), . . http://blog.abodit.com/2010/07/gdi-image-fromfile-problem/

0
source

Source: https://habr.com/ru/post/1776954/


All Articles