Facebook表情符号

时间:2011-05-19 00:17:22

标签: html css wpf facebook userscripts

此代码来自 Facebook Chat Emoticons Bar Grease Monkey UserScript

ImagesURL = HttpsOn?'https://s-static.ak.fbcdn.net/images/':'http://static.ak.fbcdn.net/images/';


emotsInfo = [':)', ':(', ':p', ':D', ':o', ';)', '8)', '8|', '>:(', ':/', ':\'(', '3:)', 'O:)', ':*', '<3', '^_^', '-_-', 'o.O', '>:O', ':v', ':3'];



for(i=0;i<emotsInfo.length;i+=1) {
        var fEmotsDom = document.createElement('img');
        fEmotsDom.setAttribute('alt',emotsInfo[i]);
        fEmotsDom.setAttribute('style','cursor: pointer; background-position: -'+ 16*i +'px 0px;');
        fEmotsDom.setAttribute('src',ImagesURL + 'blank.gif');
        fEmotsDom.setAttribute('class','emote_img');
        fEmotsListDom.appendChild(fEmotsDom);
    }


此代码从Facebook服务器带来Facebook情绪 我正在编写WPF代码,我理解所有代码程序,除了从blank.gif获取情感
C#代码

        const string EmotionsResources = "http://static.ak.fbcdn.net/images/";


        private Image Emoticons ( string E )
        {
            return ( new Image ( ) { Source = new BitmapImage ( new Uri ( EmotionsResources + E ) ) } );
        }


如果你想获得任何Facebook聊天情绪的来源......你会得到[http://static.ak.fbcdn.net/images/blank.gif] 这段代码从这个链接中检索情绪如何?

1 个答案:

答案 0 :(得分:4)

我在这里猜测,但我认为该类会触发检查alt文本的样式。 (一旦你克服了所有不可能的答案,这是唯一有效的答案。每次迭代中唯一改变的是alt文本,因此必须触发它。而css类选择器可以处理属性值)

换句话说 - 你被困住了。


修改

所以我很感兴趣,所以我开始深入挖掘:

图像上的css样式中包含以下css规则:

element.style {
background-position: 0px 0px;
}
.emote_img {
background: url(http://static.ak.fbcdn.net/rsrc.php/v1/zC/r/eKCEtE1PXyK.png) no-repeat;
overflow: hidden;
}

第一个由脚本设置,第二个来自CSS文件。

如此。实际图像可以在那个png文件中找到,即:

http://static.ak.fbcdn.net/rsrc.php/v1/zC/r/eKCEtE1PXyK.pngfacebook emoticon sprite http://static.ak.fbcdn.net/rsrc.php/v1/zC/r/eKCEtE1PXyK.png

(很酷,知道你可以在fb中使用这么多的表情符号!: - )

你会在一张图片中看到所有图片(这样做是为了保留带宽) 由于图像尺寸为16 * 16,因此一次仅显示一个图像。 background-position thingie负责移动图像,以便每次从大图像中显示不同的图标。


因此,要在C#中获取图像,您将执行以下操作:

你可以裁剪它,或使用完全相同的技巧(这是更好的IMO),如下所示:

<Canvas ClipToBounds="true" Width="16" Height="16">
    <Image Source="http://static.ak.fbcdn.net/rsrc.php/v1/zC/r/eKCEtE1PXyK.png" 
       Canvas.Left="0" /> <!-- or -16, -32, -48 etc.. -->
</Canvas>
相关问题