Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6349989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:43:31+00:00 2026-05-24T21:43:31+00:00

I have done this one for converting the byte of array in one of

  • 0

I have done this one for converting the byte of array in one of the columns in gridview to system.drawing.image got an error at this line

Image returnImage = Image.FromStream(ms);        

              argumentexception was unhandled 
              Parameter is not valid.

and the code is like this

private byte[] objtoarray(object obj)
{         
    if (obj == null)
        return null;

    BinaryFormatter bf = new BinaryFormatter();
    MemoryStream ms = new MemoryStream();
    bf.Serialize(ms, obj);

    return ms.ToArray();

}

public Image bytearraytoimage(byte[] bytearray)
{
    MemoryStream ms = new MemoryStream(bytearray,0,bytearray.Length);

    Image returnImage = Image.FromStream(ms);
    return returnImage;

}

private void productGridview_Cellclick(object sender, DataGridViewCellEventArgs e)
{
    byte[] bits = null;
    Image img = null;

    if (e.ColumnIndex != productgridview.Columns["productimage"].Index) return;

    if (productgridview.SelectedCells.Count == 0) return;

    object selectedValue = productgridview.SelectedCells[0].Value;
    bits= objtoarray(selectedValue);
    img = bytearraytoimage(bits);

    if (img is Image)
    {
        // Forms are IDisposable, so use them embedded in a using statement.
        using (ProductDescriptionForm pf = new ProductDescriptionForm())
        {
            pf.picture = (Image)selectedValue;
            pf.ShowDialog(this);
        }
    }      
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:43:32+00:00Added an answer on May 24, 2026 at 9:43 pm

    The docs state that ArgumentException can be raise for :

    The stream does not have a valid image format
    -or-
    stream is null.
    

    So since objtoarray can return null, is productgridview.SelectedCells[0].Value null, or of an invalid value?

        object selectedValue = productgridview.SelectedCells[0].Value;
        bits= objtoarray(selectedValue);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In C++ I have only seen this done by converting the string object into
I have done this: $ z() { echo 'hello world'; } How do I
I have done this operation millions of times, just using the + operator! I
I could have sworn i have done this somewhere - im using 2.0 right
I need to create a Firebird Database programmatically using DBExpress. I have done this
I want to make a development server for Ruby. (I have done this for
I'm currently working on wholesale online t-shirt shop. I have done this for fixed
Has anyone done this / have some example code?
i have done something like this: <form action=validate.php method=get> Id :<input type=text name=pID/><br/><br/> Name
I'm looking for a simple way to have this done. I would to have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.