2012-12-12 65 views
1

我有一個從簽名捕獲中捕獲的圖像。 sig cap返回圖像的base64字符串。插入一個base64位圖到rtf中

我想創建一個rtf文件字符串與它裏面的這個圖像從JavaScript。

在這裏我有什麼:

var datapair = $sigdiv.jSignature("getData"); 

它返回(因爲縮短長SO張貼):

["data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABNMAAAE2CAYAAABLINTeAAAgAElEQVR4Xu3dCbQtVXkgYPMYRVBAxTi0PkQDmCCgxiESeaBtCK0IGqKJEUzAuUFNtF1Jx/CcVnezYhSMtigYwJjYTgyRaFqNF+chYdBoVEQejgFRURNh4UD/v55qy/Lce88595w6tau+Wutf9wxVe//72/XOved/NfzCLSwECBAgQIAAAQIE2hO4W3S1edTdrvFzn4grI/599NqB8XOPWjor66R2SLy/LeI/phjCA2Ldjy5w/arpW43G+oE1+lptvONsLo92rp8ib6sSIECAAAECCxD4hQW0qUkCQIECBAgQIAAAQIECBBoWUAxrWVw3REgQIAAAQIECBAgQIAAAQIECJQroJhW7tzJnAABAgQIECBAgAABAgQIECBAoGUBxbSWwXVHgAABAgQIECBAgAABAgQIECBQroBiWrlzJ3MCBAgQIECAAAECBAgQIECAAIGWBRTTWgbXHQECBAgQIECAAAECBAgQIECAQLkCimnlzp3MCRAgQIAAAQIECBAgQIAAAQIEWhZQTGsZXHcECBAgQIAAAQIECBAgQIAAAQLlCiimlTt3MidAgAABAgQIECBAgAABAgQIEGhZQDGtZXDdESBAgAABAgQIECBAgAABAgQIlCugmFbu3MmcAAECBAgQIECAAAECBAgQIECgZQHFtJbBdUeAAAECBAgQIECAAAECBAgQIFCugGJauXMncwIECBAgQIAAAQIECBAgQIAAgZYFFNNaBtcdAQIECBAgQIAAAQIECBAgQIBAuQKKaeXOncwJECBAgAABAgQIECBAgAABAgRaFlBMaxlcdwQIECBAgAABAgQIECBAgAABAuUKKKaVO3cyJ0CAAAECBAgQIECAAAECBAgQaFlAMa1lcN0RIECAAAECBAgQIECAAAECBAiUK6CYVu7cyZwAAQIECBAgQIAAAQIECBAgQKBlAcW0lsF1R4AAAQIECBAgQIAAAQIECBAgUK6AYlq5cydzAgQIECBAgAABAgQIECBAgACBlgX+H9F/EpGfbmFGAAAAAElFTkSuQmCC"] 

我然後我試圖形成具有以下字符串的RTF文檔。

string rtf = @"{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard "; 
      rtf += picture; 
      rtf += " }"; 
      return rtf; 

凡圖片(縮短,因爲長期張貼在SO):

var imageData = "iVBORw0KGgoAAAANSUhEUgAABNMAAAE2CAYAAABLINTeAAAgAElEQVR4Xu3dC9A1ZX0YcMOHYlEI0GhMk9EPiLU6NULEptUqL0irphb5IB0ZIxeVljEtl6ixM5kAH5dMR8dLwMY28cIltdgIcnHUdtTwUmsTdUCZxNRqlA9jvTSZfp/FCyKX/v961i7Led93z3nP2bPP7u/M/OfsOWd3n//ze5b3fOfPs7s/8QgPAgQIECBAgAABAgQIECBAgAABAgRaCfxEq7WsRIAAAQIECBAgQIAAAQIECBAgQIDAIxTTHAQECBAgQIAAAQIECBAgQIAAAQIEWgooprWEshoBAgQIECBAgAABAgQIECBAgAABxTTHAAECBAgQIECAAAECBAgQIECAAIGWAoppLaGsRoAAAQIECBAgQIAAAQIECBAgQEAxzTFAgAABAgQIECBAgAABAgQIECBAoKWAYlpLKKsRIECAAAECBAgQIECAAAECBAgQUExzDBAgQIAAAQIECBAgQIAAAQIECBBoKaCY1hLKagQIECBAgAABAgQIECBAgAABAgQU0xwDBAgQIECAAAECBAgQIECAAAECBFoKKKa1hLIaAQIECBAgQIAAAQIECBAgQIAAAcU0xwABoJjWMbjmCBAgQIAAAQIECBAgQIAAAQIEyhVQTCt37GROgAABAgQIECBAgAABAgQIECDQsYBiWsfgmiNAgAABAgQIECBAgAABAgQIEChXQDGt3LGTOQECBAgQIECAAAECBAgQIECAQMcCimkdg2uOAAECBAgQIECAAAECBAgQIECgXAHFtHLHTuYECBAgQIAAAQIECBAgQIAAAQIdCyimdQyuOQIECBAgQIAAAQIECBAgQIAAgXIFFNPKHTuZEyBAgAABAgQIECBAgAABAgQIdCygmNYxuOYIECBAgAABAgQIECBAgAABAgTKFVBMK3fsZE6AAAECBAgQIECAAAECBAgQINCxgGJax+CaI0CAAAECBAgQIECAAAECBAgQKFdAMa3csZM5AQIECBAgQIAAAQIECBAgQIBAxwKKaR2Da44AAQIECBAgQIAAAQIECBAgQKBcAcW0csdO5gQIECBAgAABAgQIECBAgAABAh0L/D9S+8lzAOsdUQAAAABJRU5ErkJggg=="; 
var picture = "{\pict\pngblip\picw1693\pich1693\picwgoal960\pichgoal960" + imagedata; 

我那麼字符串賦值給一個格式文本框(樣本WinForms應用程序,我只是想證明rtf文件有效)。顯示

this.richTextBox1.Rtf = rtf; 

沒什麼=(

+1

在看http://stackoverflow.com/questions/1490734/programatically-adding-images-to-rtf-document和鏈接http://stackoverflow.com/questions/542850/how-cani-i- insert-an-image-into-a-richtextbox很明顯數據必須是**十六進制編碼**而不是base64。 –

回答

2

我看到兩個主要問題與你正在嘗試做的。 首先,RTF需要媒體是十六進制編碼,而不是Base64編碼。因此,首先你的圖像數據轉換成。一個十六進制字符串然後,你需要改變你如何建立你的RTF畫面的微小變化,但它應該有所作爲更改變種圖片如下:。

var picture = "{\pict\picw1693\pich1693\picwgoal960\pichgoal960\pngblip" + imagedata; 

\ pngblip就是告訴RTF閱讀器圖片數據即將到來