作者: Miklogak
查看: 489|回复: 1
打印 上一主题 下一主题

[源码] 【RTF文本框】在 RichTextBox 中自动加载笑脸

[复制链接]
楼主
qiaoke_song 发表于 2022-12-25 19:30:41 | 显示全部楼层
本帖最后由 qiaoke_song 于 2022-12-25 19:35 编辑

RichTextBox这个东西么,主要是写入了图像要读取出来用的。解决的深入一点,参考下。注意下.net4.5以下
winform的,可以优化修改
链接:https://pan.baidu.com/s/1CtVLACvGVQQIktv3TWovhg
提取码:hk0z

wpf的
http://bbs.cskin.net/thread-15573-1-1.html

winform的麻烦一些,要找结构写入才能读取,
        byte[] _FileBytes = File.ReadAllBytes(p_FileFullPath);
        Image _Image = Image.FromStream(new MemoryStream(_FileBytes));
        string _Guid = BitConverter.ToString(Guid.NewGuid().ToByteArray()).Replace("-", "");
        StringBuilder _RtfText = new StringBuilder(@"{\rtf1\ansi\ansicpg936\deff0\deflang1033\deflangfe2052{\fonttbl{\f0\fnil\fcharset134 \'cb\'ce\'cc\'e5;}}\uc1\pard\lang2052\f0\fs18{\object\objemb{\*\objclass Paint.Picture}");
        _RtfText.Append(@"\objw" + _Width.ToString() + @"\objh" + _Height.ToString());
        _RtfText.AppendLine(@"{\*\objdata");
        _RtfText.AppendLine(@"010500000200000007000000504272757368000000000000000000" + BitConverter.ToString(BitConverter.GetBytes(_FileBytes.Length + 20)).Replace("-", ""));
        _RtfText.Append("7A676B65" + _Guid);         
        _RtfText.AppendLine(BitConverter.ToString(_FileBytes).Replace("-", ""));
        _RtfText.AppendLine(@"0105000000000000}{\result{\pict\wmetafile0}}}}");
        base.SelectedRtf = _RtfText.ToString();

wpf的简单多了
Image image = new Image()
        {
            Width = imagesize,
            Height = imagesize,
            UseLayoutRounding = true,
            Source = new BitmapImage(new Uri(imageUrl, UriKind.RelativeOrAbsolute))
        };
        new InlineUIContainer(image, rtb.Selection.Start);
您需要登录后才可以回帖 登录 | 加入CSkin博客

本版积分规则

QQ|申请友链|小黑屋|手机版|Archiver|CSkin ( 粤ICP备13070794号

Powered by Discuz! X3.2  © 2001-2013 Comsenz Inc.  Designed by ARTERY.cn
GMT+8, 2024-5-7 03:03, Processed in 0.526844 second(s), 28 queries , Gzip On.

快速回复 返回顶部 返回列表