我的目标是创建一个eBook,我可以在黑莓上用Mobi便携阅读器阅读它。问题是,我的文本包含UTF-8字符,这些字符在黑莓上不受支持,因此显示为黑匣子。
eBook将包含一份可供参考的英语和旁遮普单词清单,例如:
bait ਦਾਣਾ
baked ਭੁੰਨਿਆ
balance ਵਿਚਾਰ其中一个想法是将列表写到HTML表中,旁遮普将其转换为GIF或PNG文件。然后在eBook中包含这个HTML文件。所有单词目前都存在于access数据库中,但是可以很容易地导出到另一种形式,以便输入到生成例程中。
问题:使用VB、VBA或C#编写一个例程创建图像,然后在表中输出包含英文单词和图像的文件有多难?
发布于 2009-02-26 06:23:47
使用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发布于 2009-02-26 01:48:48
Python中有处理此类问题的简单库。但是,我不确定是否有一个微不足道的VB/C#解决方案。
对于python,您将使用类似于此的PIL文库和代码(我找到了这里):
# 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来处理生成的图像。这个这里有一些例子。
https://stackoverflow.com/questions/588726
复制相似问题