.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

XmlSerializer: Serialize an array of System.Drawing.Color

Posted By:      Posted Date: September 07, 2010    Points: 0   Category :.NET Framework
Ok,  here is my problem... I am building a UI configuration tool that utiliizes a PropertyGrid.  One of the properties is a indexed list of Colors contained in an array: CategoryAttribute("Style"), DisplayName("Data Set Colors"), DescriptionAttribute(""), XmlArray("SetColors"), XmlArrayItem(ElementName="Color",Type=typeof(SColor))] public Color[] SetColors { get; set; } The beauty of the PropertyGrid is it knows how to handle this Poperty and properly handles array and list of Colors. BUT...   As we already know in order to serialize a Color,  we have to use a surrigate property,  which is very unfortunate, and I fear is one of those little thing MS just overlooked.  (I understand it is actually a structure and not a class and has not default properties from which to get type info from.) I am really amazed that when I do serialize the class,  the XML is soooo  close to what I need,  its just missing the actual color value data: <AppGridColumnConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Name>Label</Name> <SetColors> <Color /> <Color /> <Color /> </SetColors> <IsDefaultEditable>false</IsDefaultEditable> <IsDirtyCheck&

View Complete Post

More Related Resource Links



Hi there,


 I am doing one task on asp.net graphics. i would like to a form that let the user choose the color code from the color picker.

inside my backend code, i can get the color code and convert to the system.drawing.color.



Dim col As System.Drawing.Color = System.Drawing.ColorTranslator.FromHtml("#9932CC")

 Dim Brush As New SolidBrush(col)


but i have some problem in make this col object to alpha color. as i know the .net code that make the system color to become alpha is wrote as like tat :

gr.DrawString(strWatermarkText, wmFont, New SolidBrush(Color.FromArgb(8, 0, 0, 0)), x, y)


May someone share me how to make the color input from form to become alpha color? thanx in advanced. hope to hear from you all soon 


System.Drawing.Image.Fromfile is not working


I am trying to get the height and width of the image dynamically.  The reason is I am loading multiple images using code, where the image name is from the database. 

Here is my code:

in the ascx page, I have an asp image

<asp:image id="imgInfo" runat="server" /> 


In the code behind

string ImagePath = "~/products/img/" + dataviewImgInfo[0]["imgName"].ToString();

System.Drawing Image imgProd = System.Drawing.Image.FromFile(ImagePath);

if(imgProd.Height > 200)

imgInfo.Height = 100;




imgInfo.Height = 200



WHen I run this page I am getting the folloiwng error

EventType clr20r3, P1 devenv.exe, P2 9.0.30729.1, P3 488f2b50, P4 system.drawing, P5, P6 488

Hi,I am facing a strange issue in Visual Studio 2008 Standard SP1, when using WPF Designer (even without using the Designer tab, only XAML tab). Visual Studio crashes very often, without any apparent reason, and in various ways, for example: exits instantly, the IDE displays corrupted UI, when begining compiling it stops responding.There are two new Event Log entries after this: EventType clr20r3, P1 devenv.exe, P2 9.0.30729.1, P3 488f2b50, P4 system.drawing, P5, P6 4889dec2, P7 33d, P8 18, P9 system.outofmemoryexception, P10 NIL. .NET Runtime version 2.0.50727.3053 - Fatal Execution Engine Error (7A2E0F92) (0)Worth mentioning:- computer has Windows XP SP3 with the latest updates installed- it crashes on other computer types too- the project has quite a large number of UserControls - it appears that if opening a XAML file with the XML editor instead, it works ok- on other WPF projects it also works okDoes anyone have an ideea why is this happening and solutions? Thanks

How to: Serialize Hashtable contained inside another object that is serialized as an array of object

Update:  I've added the entire program in a single block of C# text near the end of these posts that can be placed into a C# Program.cs file of a console project.   I have a class called MyHashtable that inherits from Hashtable and implements IXmlSerializable.  MyHashtable is contained inside another object called MyObject and I need to xml serialize an array of MyObject[].  Whenever I xml deserialize, the hashtable is deserialized, but only 1 of MyObjects from the MyObject[] array is deserialized.  The ReadXml uses "while (reader.NodeType != XmlNodeType.EndElement)" so I don't think the reader is consuming all of the xml internally.   Does anyone know why this is happening?  Thanks.    

Displaying a System.Drawing.Bitmap in a WPF Image control

How would I convert a System.Drawing.Btimap into a comparable WPF image control so I can display in on my WPF window? Thanks

Can serialize but not deserialize class containing an xs:list attribute using XmlSerializer

I have a simple serializable class along the lines of: [Serializable] [XmlType] public class MyClass { [XmlAttribute("values")] public int[] Values { get; set; } } If I create an instance of this class with Values set to an empty collection the XmlSerializer class produces this output as expected: <?xml version="1.0" encoding="utf-16" ?> <MyClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" values="" /> However, deserializing this exact output throws a System.FormatException: Input string was not in a correct format. Shouldn't the XmlSerializer be able to deserialize this, since it produced the xml string in the first place?

Converting System.Windows.Media to System.Drawing objects

Hello, I want to know if it's possible to convert the System.Windows.Media objects Color and Imaging.BitmapSource to the System.Drawing objects Color and Bitmap and the other way around. If yes, how can I do this?

Serialize parameter array

Hello again, Since there was no response to my first attempt, I shall re-phrase my question. What I need to do is save an object to an image column in an sql database. Now, as I understand it, any object can be serialized as long as it implements ISerializable. So I did that. Now I run into the issue of - the objects members must implement ISerializable as well. The reason for this is that I need to be able to execute several sqlcommands to create a object containing several datatables. What I need to do is save the parameters (search criteria) somehow so that I can execute the queries at a later time. I am thinking that I can make my own object which is composed of the several SqlParameter arrays, and convert it to a byte[] for inserting into a database as a "saved search criteria" or even put into the ViewState of a webform so that the page can execute the query without going thought the complex process of gather the values from the ui and creating the SqlParameters. Here is what I would like to persist to a byte[]. I have a simple collection of SqlParameter arrays. i.e - [Serializable()] public class SavedCriteria : ISerializable { public SqlParameter[] Params1; public SqlParameter[] Params2; //implement ISerializable public void GetObjectData(SerializationInfo info, StreamingContext context) {

Converting a System.Windows.Control.Image object to byte array.

Hi i need to convert a specific System.Windows.Control.Image object into an (int) array, because i'm trying to convert a silverlight application into a wpf project. private void createGi02GradBrush()<br/> {<br/> WriteableBitmap oWriteableBitmap = new WriteableBitmap(256, 256);<br/> Image oImage = new Image();<br/> oImage.Arrange(new Rect(0, 0, 256, 256));<br/> oImage.Measure(new Size(256, 256));<br/> oImage.Source = new WriteableBitmap(256, 256);<br/> Gi02GradShaderEffect oGi02GradShaderEffect = new Gi02GradShaderEffect();<br/> oGi02GradShaderEffect.pArray = oPImageBrush;<br/> oGi02GradShaderEffect.gi1GradArray = oGi1GradImageBrush;<br/> oImage.Effect = oGi02GradShaderEffect;<br/> oWriteableBitmap.Render(oImage, null);//here<br/> oWriteableBitmap.Invalidate(); <br/> this.oGi02GradImageBrush = new ImageBrush();<br/> this.oGi02GradImageBrush.ImageSource = oWriteableBitmap;<br/> } I've found some similar topics however Image object is not the same and most of its methods aren't available. Here I'm rendering a writablebitmap with a given Image object, but in wpf we need an array. oWriteableBitmap.Render(oImage, null); Any idea? Thanks. Joseph.  

Textbox error count is not member of system Array

HiI am trying to measure the number of lines in a textbox using Dim pos As Integer = tags.Lines.Count And I am getting count is not member of system Array which is wired as the same textbox in a different application returns no such error. Any ideas what is wrong is this some kind of Studio bug?

First Steps with VS2010 RC - System.Drawing; missing?

I'm a little confused! I was curious about the new VS2010 RC and as I wanted to start with a new Software Project I  wanted to give it a try. 1. Installation troubble with Silverlight but VS2010 loads without errors. 2. Now I wanted to try out this things with a full aero window and found a nice and simple code snipplet on the MSDN .NET FW4 Extend Glass Frame Into a WPF Application So I made this short changes in my first source code and I'm getting the strange message: Error    1    The type or namespace name 'Drawing' does not exist in the namespace 'System' (are you missing an assembly reference?)    D:\Projekte\Selfmade\Software\CAS_Information\CAS_Information\MainWindow.xaml.cs    19    14    CAS_Information I found a lot of c# code with a using System.Drawing; but on my installation I dont have such a namespace. What the heck is wrong there?   Windows 7 x64 - VS2010 RC

'System.Array' does not contain a definition for 'FirstOrDefault'

'System.Array' does not contain a definition for 'FirstOrDefault' and no extension method 'FirstOrDefault' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?) What am i missing Ctrl . does not work here ( I am using MVC 2) :( its for getting the string length from the metadata of a class var stringLength = member.Member.GetCustomAttributes(typeof(StringLengthAttribute), false).FirstOrDefault() as StringLengthAttribute;  Its part of some code i found on the net for a custom helper to create textboxfor with Maxlength without having to add to to ever textbox for manually.   But it is not compliing    

System.Drawing.Image.FromFile crashes for tiff files on 64bit system


The following pice of code runs fine on my development machine (win7, 32bit) but ends with Exception on the server (Win2008R2, 64bit).


        static void Main(string[] args)


            Image image = Image.FromFile(args[0]);





The exception will be thrown for TIFF files (from other sources) but ie not for PNG files.

I was wondering why the test program above works fine on my Win 32bit machine with .NET 4 but not on my 64bit machine with .NET 4.

Any help appreciated.



Use System.Drawing class



How can I to use System.Drawing.Bitmap class into athoer class?

using System.Data;
using System.Collections;
using System.Globalization;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Globalization;
using System.Text;

namespace University
    public class Class1

      System.Drawing.Bitmap BMP=new System.Drawing .Bitmap();



when I use System.Drawing.Bitmap gives error this class does not exists !!!!!!!!

How to Convert System.Drawing.Image Variable to Byte variable



I got a variable of type System.Drawing.Image and need to convert it to a variable of type byte so I can store the image in the database. Can someone show me how to do that in VB.NET code.

Thanks alot

Unable to cast COM oject of type 'System.__ComObject' to class type of 'System.Drawing.Bitmap' .

 private void DirectXViewer_DragDrop(object sender, DragEventArgs e)


   mousePressedFlag = false;



    Object obj = e.Data.GetData(typeof(Bitmap));





      Bitmap image = (Bitmap)((Bitmap)obj).Clone();

      RenderImage = image;



     catch(Exception ex)








private void DirectXViewer_MouseMove(object sender, MouseEventArgs e)


   if (mousePressedFlag)


    if(cacheBitmap != null)

     this.DoDragDrop(new Bitmap(cacheBitmap), DragDropEffects.Copy);




Hi All,

I try to d

Get Image from HTTP in a System.Drawing.Image


How can i get a Image that exitsts on the WWW, into my project.
Normally i get a image on this way:


        System.Drawing.Image ImgWatermerk = System.Drawing.Image.FromFile(PNGPath);


But right now the image is remote like http://www.google.nl/google.jpg


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend