2009-02-26 17 views
0

我的目標是創建一本電子書,我可以使用我的黑莓上的Mobipocket閱讀器閱讀。問題是我的文本包含黑莓手機不支持的UTF-8字符,因此顯示爲黑匣子。在電子書中使用GIF或PNG輸出文本

電子書將包含英語和旁遮普語單詞供參考,如列表:

bait   ਦਾਣਾ 
baked  ਭੁੰਨਿਆ 
balance  ਵਿਚਾਰ 

我想過是列表中寫入與旁遮普的HTML表格轉換爲GIF或PNG文件。然後將這個HTML文件包含在電子書中。所有這些單詞目前都存在於訪問數據庫中,但可以很容易地導出到另一個表單以輸入到生成例程。

問題:使用VB,VBA或C#,如何努力會是寫一個程序創建的圖像,然後輸出包含表格中英文文字和圖片的HTML文件

回答

2

使用VB

Sub createPNG(ByVal pngString As String, ByVal pngName As String) 

' Set up Font 
Dim pngFont As New Font("Raavi", 14) 

' Create a bitmap so we can create the Grapics object 
Dim bm As Bitmap = New Bitmap(1, 1) 
Dim gs As Graphics = Graphics.FromImage(bm) 

' Measure string. 
Dim pngSize As SizeF = gs.MeasureString(pngString, pngFont) 

' Resize the bitmap so the width and height of the text 
bm = New Bitmap(Convert.ToInt32(pngSize.Width), Convert.ToInt32(pngSize.Height)) 

' Render the bitmap 
gs = Graphics.FromImage(bm) 
gs.Clear(Color.White) 
gs.TextRenderingHint = TextRenderingHint.AntiAlias 
gs.DrawString(pngString, pngFont, Brushes.Firebrick, 0, 0) 
gs.Flush() 


'Saving this as a PNG file 
Dim myFileOut As FileStream = New FileStream(pngName + ".png", FileMode.Create) 
bm.Save(myFileOut, ImageFormat.Png) 
myFileOut.Close() 
End Sub 
4

有容易庫在Python中處理這類問題。但是我不確定是否有一個簡單的VB/C#解決方案。

與Python你會使用類似的PIL library和代碼(我發現here):

# creates a 50x50 pixel black box with hello world written in white, 8 point Arial text 
import Image, ImageDraw, ImageFont 

i = Image.new("RGB", (50,50)) 
d = ImageDraw.Draw(i) 
f = ImageFont.truetype("Arial.ttf", 8) 
d.text((0,0), "hello world", font=f) 
i.save(open("helloworld.png", "wb"), "PNG") 

如果你已經熟悉其他語言的Python應該是很容易回升,不像VB/C#可以在任何平臺上運行。 Python還可以幫助您生成HTML以與生成的圖像一起移動。有一些here的例子。

+0

不錯完整的答案 - 用引文 – 2009-02-26 01:52:36

相關問題