Skip to content

Getting image from database

Kvr Krishna

Kvr Krishna

Asked Oct 13, 2016, 2:49 AM EDT3 answers
Share
LinkedInX
Hi,
While reading a image from database i am not getting full image, i'm getting some upper part of the image only. My image is stored in binary format in database (varbinary(Max)). If image size is less then 20kb i am getting full image. Ex. if i select mobile it is showing like below image, what i want is full image. Here i don't want to use any handlers, Displaying in same page. i am using SQL-2014, MSVS-2015(c#, Asp.Net).

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    where you give asp image tag there you should bind your imageurl="data:image/png;base64,"+ Convert.ToBase64String((byte[]) Eval["your image column name"] )
    Code
     Or
    Java
    Stream strm = upload1.PostedFile.InputStream;
    BinaryReader reader = new BinaryReader(strm);
    Byte[] bytes = reader.ReadBytes(Convert.ToInt32(strm.Length));
    imgDetail.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(bytes, 0, bytes.Length);
    imgDetail.Visible = true;

    0
  • Kvr Krishna
    0
    Hi mehul,
    In the above screenshot right side below is my code
    Java
    SqlCommand cmd = new SqlCommand("proc_take", con);
                    cmd.CommandType = CommandType.StoredProcedure;
    
                    byte[] b = (byte[])cmd.ExecuteScalar();
                    string Base64String = Convert.ToBase64String(b);
    Image1.ImageUrl = "data:image/jpg;base64," + Base64String;
    was my code. I am converting and assigning to Image control. Here the actual problem is i am getting some part of the image only as shown in left side DDL, black mobile.
    What should i do to get full image.
    0
  • 0
    Buddy rather than taking time to your code please try other options like one i suggested .i can tell you methods how can you show an image but it's more time consuming for me that why it should be show some portion of image.
    but after seems your code it is definatly related to some mistake in your code .so pls do some alteration in your code. i think your variable of type byte(b) can't contain full length.
    imgDetail.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(b, 0, b.Length);
    0