1

以下のコードを使用してビットマップを作成しています。画像は作成されていますが、指定されたサイズではありません。コードに問題はありますか?

public class ProcessImage : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        var bmpOut = new Bitmap(100, 100);
        var request = (HttpWebRequest)WebRequest.Create("http://media.zenfs.com/en_us/Sports/ap/201305061639599673916-p2.jpeg");
        request.AllowWriteStreamBuffering = true;
        var response = (HttpWebResponse) request.GetResponse();
        var myStream = response.GetResponseStream();
        var b = new Bitmap(myStream);
        var g = Graphics.FromImage(bmpOut);
        g.InterpolationMode = InterpolationMode.High;
        g.DrawImage(b,0,0,50, 50);
        context.Response.ContentType = "image/png";
        var stream = new MemoryStream();
        b.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
        b.Dispose();
        stream.WriteTo(HttpContext.Current.Response.OutputStream);
        //context.Response.Write("Hello World");
    }
4

1 に答える 1

3
private Bitmap ResizeImage(Image image, int width, int height)
{
    Bitmap result = new Bitmap(width, height);
    result.SetResolution(image.HorizontalResolution, image.VerticalResolution);
    using (Graphics graphics = Graphics.FromImage(result))
    {
        graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
        graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

        graphics.DrawImage(image, 0, 0, result.Width, result.Height);
    }
    return result;
}
于 2013-05-29T05:51:33.757 に答える