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

  • Home
  • SEARCH
  • 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 6061837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:58:58+00:00 2026-05-23T08:58:58+00:00

public Image Image { get; set; } Image=(Image)randomImageFromCommentsClass.Image; I get this: Cannot convert System.Drawing.Image

  • 0

public Image Image { get; set; }

Image=(Image)randomImageFromCommentsClass.Image;

I get this:

Cannot convert System.Drawing.Image to System.Web.UI.WebControls

I think I imported the wrong namespace (System.Drawing)..That may be the mistake. What I am trying to do is to convert the Image type from database to an Image object.

public class Comments
{
  public Image Image { get; set; }
      Image = DBNull.Value.Equals(dr["Avatar"]) ? null: (Image)dr["Image"];

This image property above is from a different class code file in visual studio 2010.

Somehow the cast fails..how do i fix that?

  • 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-23T08:58:59+00:00Added an answer on May 23, 2026 at 8:58 am

    There is definitely no way you will be able to cast unless the object you are casting is an instance of the other object.

    You can covert the byte array to an Image with this snipet:

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

    To show a dynamically created image with your WebControl you will need a handler more info here:

    Serving Dynamic Content with HTTP Handlers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public Image Base64ToImage(string base64String) { // Convert Base64 String to byte[] byte[] imageBytes =
I have hierarchy: public class Parameter { public string Name { get; set; }
I have set ridiculous padding values and cannot get padding to extend the total
I have an object that has a property: [Column] public Binary Image { get;
public class RegisterSubscription { public string ID { get; set; } public string Description
i build that class using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI.WebControls;
How can i use Tomcat to serve image files from a public folder outside
I have a class Image implementing ISerializable : [Serializable] [XmlRoot(ElementName = IMAGE)] [TypeConverter(typeof(ImageTypeConverter))] public
I'm looking for an algorithm that rotates an image by some degrees (input). public
package test; import java.awt.*; import java.awt.event.*; import java.awt.geom.Ellipse2D; import java.awt.image.BufferedImage; import javax.swing.*; public class

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.