Mutual inversion between emoticon images and emoticon codes in RTF

Source: Internet
Author: User

I posted a post on the Forum about how to convert the inserted image into a custom emoticons code in RTF.

And reversible.

Http://community.csdn.net/Expert/topic/3874/3874035.xml? Temp =. 2201197.

First of all, I would like to thank the friends who made suggestions and those who helped me. The problem was solved due to the time constraints. I would like to share with you.

Remember that there are n ways to insert an image into RichTextBox. In fact, there are only two ways in RichTextBox. One is to insert an image directly in RichTextBox starting with Pict, the two methods are ole-based embedding starting with an object. we will discuss the previous one. Because there are many codes, I will directly provide the Code project for you to download. in this case, let's talk about some solutions.

RTF does not have a flag available to identify the image (J is not found yet). Therefore, to convert the image into an emoticons code, you can only locate the Image Based on the Image Signature, however, it is too troublesome to search for 71 images. Therefore, we need to first find the minimum signature of 71 images. For the sake of simplicity, after the image is generated in hexadecimal format, select the first n Bytes. N indicates 71 different images. the method is to compare one by one (available selection and sorting) r find this n. then we generate the sequent file smile. bin, which contains the complete image, Image Signature, And emoticons represented by this image.

Forward conversion: When you want to send a message containing an emoticon image, the RTF is very large because it contains an image. we need to convert the image code into a custom emoticon Code, for example, the image is "^-^" -- à ":)".

In RTF, we can remove this part of the code and insert our custom emoticon code starting with Pict. the method is to find out the first 500 bytes of PICT (500 is N, I am here) and smile. the image signature in Bin is compared. It is strange that the image code generated by the same image twice is somewhat different (I don't know what the RichTextBox is), so a fuzzy factor is referenced, this factor is 28. Different images may be different. after matching, you can find the emoticons code.

Reverse conversion: It is to convert the emoticon code into an image, which is easier than forward. Just find the custom emoticon code in the RTF according to smile. bin to find the corresponding image file, but there is a problem here, you cannot directly display the RTF code before inserting the emoticon code in RichTextBox, because this is not complete, will lead to exceptions, must be complete, in this way, a RichTextBox must be used to convert the image.

In fact, if the RTF is directly our custom tag, it will not be so troublesome. But after assigning a value to RichTextBox directly, it will remove the tags that it deems useless (bitter)

If you have a better method, please let me know.

The effect is as follows:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.