输出文本为GIF或PNG在电子书使用
-
09-09-2019 - |
题
我的目标是创建一个我可以在我的黑莓的Mobipocket的读者阅读电子书。的问题是,我的文本包括未支撑在黑莓UTF-8字符,因此显示为黑盒子。
在电子书将包含英语和旁遮普字作参考,例如列表:
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
其他提示
有容易库的Python为处理这类问题。但是我不知道是否有一个简单的VB / C#解决方案。
# 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#将工作在几乎任何平台。蟒蛇也可以帮助你生成HTML与生成的图像一起去。有此这里。
不隶属于 StackOverflow