4

此代码来自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 ] 此代码从此链接检索情绪如何?

4

1 回答 1

4

我在这里猜测,但我认为该类触发了一种检查替代文本的样式。(这是唯一有效的答案,一旦你划掉所有不可能的答案。每次迭代中唯一改变的是 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.png脸书表情精灵

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

由于图像大小为 16*16,因此您将在一张图像中看到所有图像(这样做是为了节省带宽),它一次只显示一张图像。背景位置的东西负责移动图像,以便每次从大图像中显示一个不同的图标。


因此,要在 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>
于 2011-05-19T00:46:02.743 回答