How can I use ImageFormatConverter.ConvertFromString to convert a string containing HTML response to an image?

前端 未结 1 422
情深已故
情深已故 2021-01-22 03:39

This is what I achieved:

in pageload

{
    panelmain.Controls.Add(abc);
    panelmain.Controls.Add(grid1);
    string toexport;
    toexport = RenderCo         


        
1条回答
  •  臣服心动
    2021-01-22 04:09

    You may have misinterpreted the documentation of ConvertFromString here, explanation:

    You are using an ImageformatConverter class which inherits and overrides TypeConverter. This means that ConvertFromString is inherited from the superclass, but because there's no way you can convert a string to an image (unless you have a vivid imagination), this method always returns null (according to documentation), or throws a NotSupportedException. This is the default behavior of the base class and an overriding class can define custom behavior, which in your case, has not been done.

    To convert from a string you will first have to define what you want. I.e., is the string a path to an image? Is it a piece of text and you want to render an image from that? Is it a Base64 encoded string that contains an image? Is it a rendered HTML page or does it contain an RTF document? Once you have an answer to these questions, you can choose the correct converter or image constructor.

    EDIT: because your question seems to be about rendering HTML as an image, check out this post at SO, as also mentioned by rchern above.

    0 讨论(0)
提交回复
热议问题