明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線(xiàn)學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

文字文件轉(zhuǎn)化為圖片文件的簡(jiǎn)易方法

[摘要]加一個(gè)picture控件 , 一個(gè)Text控件, 一個(gè)按扭控件, 名字默認(rèn)先把你要加載的文字加到Text控件之中,控件高度調(diào)整恰當(dāng)使文字容納并顯示完全,并且把Text控件和Picture控件寬度大小...
加一個(gè)picture控件 , 一個(gè)Text控件, 一個(gè)按扭控件, 名字默認(rèn)

先把你要加載的文字加到Text控件之中,控件高度調(diào)整恰當(dāng)使文字容納并顯示完全,并且把Text控件和Picture控件寬度大小調(diào)整一樣!!!如果不一樣,那么圖象就有可能放大或縮小(如果不需要這樣,你可以在下面的代碼中自行修改)

如果想要其他花樣 , 可以修改Text控件的文字屬性, 比如FontName等等
如果想要多花樣,可以加入RichTextBox控件(代碼只要把text的改成RichTextBox的即可),這樣就可以顯示RTF文件了.

加入以下代碼到窗體:


Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Private Const SRCCOPY = &HCC0020

Private Sub Command1_Click()
Dim i As Long
Dim wText As Long
Dim hText As Long
Dim w As Long
Dim h As Long
Dim hdcText As Long

Picture1.AutoRedraw = True
Picture1.Cls
wText = Text1.Width
hText = Text1.Height
w = Picture1.Width
h = Picture1.Height
hdcText = GetDC(Text1.hwnd)
i = StretchBlt(Picture1.hdc, 0, 0, w, h, hdcText, 0, 0, wText, hText, vbSrcCopy)
Picture1.Refresh
SavePicture Picture1.Image, "D:\1.bmp"
ReleaseDC Text1.hwnd,hdcText
End Sub


這是簡(jiǎn)單的方法,當(dāng)然更復(fù)雜的還有