Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

ArgumentException was unhandled by the usercode

$
0
0
HI,
        can anyone solve my problem here  i paste my code  and  in this code exception was thrown

         Exception:  ArgumentException was unhandled by the usercode
                          Parameter is not valid.

        
         Exception was occured in this line :   Bitmap loBMP = new Bitmap(str);
    
        code:

         protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string imageid = Request.QueryString["id"];
                if (imageid == null || imageid == "")
                {
                   //Set a default imageID
                    imageid = "16";
                }

                SqlConnection connection = new SqlConnection("server=Everest;initial catalog=kk;uid=sa;pwd=kk");
                connection.Open();
                SqlCommand command = new SqlCommand("select Image from tblImage where id=" + imageid, connection);
                SqlDataReader dr = command.ExecuteReader();
                dr.Read();
                Stream str = new MemoryStream((Byte[])dr["Image"]);
               
                    Bitmap loBMP = new Bitmap(str);
                    Bitmap bmpOut = new Bitmap(100, 100);
                    Graphics g = Graphics.FromImage(bmpOut);
                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    g.FillRectangle(Brushes.White, 0, 0, 100, 100);
                    g.DrawImage(loBMP, 0, 0, 100, 100);
                    MemoryStream ms = new MemoryStream();
                    bmpOut.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    byte[] bmpBytes = ms.GetBuffer();
                    bmpOut.Dispose();
                    ms.Close();
                    Response.BinaryWrite(bmpBytes);
                    connection.Close();
                    Response.End();
               
            }

thanks and regards
brite
       

Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>