0

データベースから表示されるこの画像に取り組んでいます。バイト配列をデータベースからイメージタグに表示するイメージに変換しています。

画像をアップロードする方法は次のとおりです。

$("#uploadBtn").live("click", function () {

$("#uploading")
    .ajaxStart(function () {
        $(this).show();
    })
    .ajaxComplete(function () {
        $(this).hide();
    });

$.ajaxFileUpload
    (
        {
            url: 'AjaxFileUploader.ashx?user=' + userId,
            secureuri: false,
            fileElementId: 'uploadControl',
            dataType: 'json',
            data: '{}',
            success: function (mydata) {

                alert("Image Successfully Uploaded");

                $('#imgdefaultphoto').attr('src', 'ImageRetrieval.ashx?user=' + userId); //referencing the ImageRetrieval handler

                hideUploadMask();
            },
            error: function () {

            }
        }
    )
  });

私は例外があります:

 Argument exception Parameter is not valid. at the line with (*). 

ImageRetrieval.ashx :

    public void ProcessRequest(HttpContext context)
    {
        string userid = context.Request.QueryString["user"];
        DBAccess dbacc = new DBAccess();
        DataTable dt = dbacc.getImage(userid);
        byte[] image = ((byte[])dt.Rows[0]["UserImage"]);
        System.Drawing.Image img = byteArrayToImage(image);

        MemoryStream stream = new MemoryStream();
        img.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
        img.Dispose();
        stream.Position = 0;
        byte[] data = new byte[stream.Length];
        stream.Read(data, 0, (int)stream.Length);
        stream.Dispose();
        context.Response.Clear();
        context.Response.ContentType = "image/jpeg";
        context.Response.BinaryWrite(data);
    }

    public Image byteArrayToImage(byte[] byteArrayIn)
    {
        MemoryStream ms = new MemoryStream(byteArrayIn);
        Image returnImage = Image.FromStream(ms);  // exception line (*)
        return returnImage;
    }

何か案は?

4

1 に答える 1