English 中文(简体)
我如何编订一个系统。 Windows.Media. Color object str?
原标题:How do I serialize a System.Windows.Media.Color object to an sRGB string?

我需要把WPF申请中使用的颜色编成一个数据库。 我愿利用欧洲复兴开发银行的价值观,因为这些价值观使我们更熟悉过去几年来一直在进行网络开发的那些价值观。

怎样才能从一个系统得到一夫多妻的扼杀。 Windows.Media. object?

www.un.org/Depts/DGACM/index_spanish.htm 我被关于MSDN的文件误导。 如下文“Kris”所述,<代码>ToString(方法的文件不正确。 尽管ToString()称“利用社会、文化权利委员会的渠道对肤色进行扼制”,但如果使用)方法创建的颜色,它实际上会回转载于《全球社会、文化权利国际公约》中。 它是一个无证件的特征,Ippose。

最佳回答

如果你利用科罗拉两种方式制造你的肤色。 FromRgb or Color。 从Argb, 而不是从ScRgb, 你们应当从String那里获得巨大的成果。

如果你想要人工操作,

string.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", c.A, c.R, c.G, c.B);

你们可以采用其他方式。

Note sRGB and scRGB refer to different Gulspace, ensure the Youuse.

问题回答

也可以这样做:

string myHex = new ColorConverter().ConvertToString(myColor);

我设置了处理转换和序列化的工作。 它解决了我面临的两个问题:它具有序列性,它纠正了拼写。

[Serializable]
public struct Colour
    {
    public byte A;
    public byte R;
    public byte G;
    public byte B;

    public Colour(byte a, byte r, byte g, byte b)
        {
        A = a;
        R = r;
        G = g;
        B = b;
        }

    public Colour(Color color)
        : this(color.A, color.R, color.G, color.B)
        {
        }

    public static implicit operator Colour(Color color)
        {
        return new Colour(color);
        }

    public static implicit operator Color(Colour colour)
        {
        return Color.FromArgb(colour.A, colour.R, colour.G, colour.B);
        }
    }

Just use Colour ,否则,你将使用System.Windows.Media.Color

If your purpose is to serialize to a file and deserialize back to the color object, I think you are better of to convert color to an Int32 and vice versa. It is no brainier to serialize/deserialize Int32. If this is your purpose, here is the code: Color To Int32:

        byte[] color = new byte[4];
        color[0] = Color.B;
        color[1] = Color.G;
        color[2] = Color.R;
        color[3] = Color.A;
        Int32 intColor = System.BitConverter.ToInt32(color, 0);

Int32 To Color:

byte[] bytes = System.BitConverter.GetBytes(intColor);
Color =new System.Windows.Media.Color(){B= bytes[0], G=bytes[1], R=bytes[2], A=bytes[3]};

该系统正在执行之中。 视窗:Media.Color toString() 方法,提供颜色的海码。

班级接口的Snippet

        //
        // Summary:
        //     Creates a string representation of the color using the sRGB channels.
        //
        // Returns:
        //     The string representation of the color. The default implementation represents
        //     the System.Byte values in hex form, prefixes with the # character, and starts
        //     with the alpha channel. For example, the System.Windows.Media.Color.ToString()
        //     value for System.Windows.Media.Colors.AliceBlue is #FFF0F8FF.
        public override string ToString();

你们能够从科罗氏度的A、R、G和B数值中获取,因此,你才需要将 by子改成 he子,并将 he子价值作为str子。

byte[] to hex string





相关问题
WPF convert 2d mouse click into 3d space

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25). When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)... How can I achieve ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

WPF: writing smoke tests using ViewModels

I am considering to write smoke tests for our WPF application. The question that I am faced is: should we use UI automation( or some other technology that creates a UI script), or is it good enough to ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

How do WPF Markup Extensions raise compile errors?

Certain markup extensions raise compile errors. For example StaticExtension (x:Static) raises a compile error if the referenced class cannot be found. Anyone know the mechanism for this? Is it baked ...

WPF design-time context menu

I am trying to create a custom wpf control, I m wondering how I can add some design-time features. I ve googled and can t seem to get to my goal. So here s my simple question, how can I add an entry ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签