實(shí)現(xiàn)代碼如下:
革吉ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來(lái)市場(chǎng)廣闊!成為成都創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18980820575(備注:SSL證書合作)期待與您的合作!
Dim img As Image = Image.FromFile("D:\Image\tstImage.jpg") 'tstImage是原先的圖片
Dim grfx As Graphics = Me.CreateGraphics
grfx.DrawImage(img, 0, 0, img.Width * 3, img.Height * 3) '在Form里顯示
Dim imgnew As New System.Drawing.Bitmap(img, img.Height * 3, img.Width * 3) '新建一個(gè)放大的圖片
imgnew.Save("D:\Image\tstNewImage.jpg", System.Drawing.Imaging.ImageFormat.Jpeg) '保存放大后圖片
你可以建一個(gè)Form,然后在Form里拖進(jìn)一個(gè)Button,把上面的代碼放在Button_Click事件里面,執(zhí)行就行了。
對(duì)上面代碼的解釋:
1.要獲取Graphics對(duì)象只能從某一事件的參數(shù)中獲取或者使用窗體和控件對(duì)象的CreateGraphics方法來(lái)獲取-----上面代碼使用Me.CreateGraphics來(lái)引用這個(gè)對(duì)象。
2.加載一個(gè)圖片用Image類的FromFile或者FromStream方法
3.用DrawImage來(lái)顯示一個(gè)圖片,該方法有30多個(gè)重載方法,可以查MSDN了解細(xì)節(jié)。
4.保存時(shí)的一個(gè)問(wèn)題:我們必須先建一個(gè)對(duì)象,用于存縮放圖像。
假如b窗體是form2,在a窗體中調(diào)用B窗體,直接dim frm as new form2,然后frm.show()就OK
byte[] bytes=(byte[])dt.Rows[0]["Photo"];
System.IO.MemoryStream ms=new System.IO.MemoryStream(bytes);
pictureBox1.Image=Image.FromStream(ms);
'這個(gè)拿去試一試,兩個(gè)圖片框,一個(gè)用來(lái)適應(yīng)圖片,一個(gè)用來(lái)適應(yīng)窗體
'兩個(gè)按鈕控件,一個(gè)用來(lái)顯示圖片,一個(gè)用來(lái)隱藏圖片
'兩個(gè)時(shí)鐘控件一個(gè)用來(lái)控制顯示速度,一個(gè)用來(lái)選擇圖片
'圖片文件夾自己建,放在文件夾當(dāng)前目錄下
'試過(guò)了,沒(méi)問(wèn)題.要還需要?jiǎng)e的顯示模式,提出要求
Dim Pic_num As Long
Dim Pic_Name() As String
Dim pic_star As Long
Dim p_width As Single
Dim p_height As Single
Dim bili_w As Single
Dim bili_h As Single
Private Sub Command1_Click() '加載并顯示圖片
If Pic_num 0 Then
Timer1.Enabled = True
Timer1.Interval = 2000
Else
MsgBox ("沒(méi)有圖片顯示!")
End If
End Sub
Private Sub Command2_Click()
Picture1.Picture = Nothing '隱藏圖片
Picture2.Cls
Timer1.Enabled = False
Timer2.Enabled = False
End Sub
Private Sub Form_Load()
Dim L_name As String
Pic_num = 0
ReDim Pic_Name(Pic_num)
L_name = Dir(App.Path "\pic\*.JPG")
Do While L_name ""
ReDim Preserve Pic_Name(Pic_num)
Pic_Name(Pic_num) = L_name
Pic_num = Pic_num + 1
L_name = Dir
Loop
L_name = Dir(App.Path "\pic\*.BMP")
Do While L_name ""
ReDim Preserve Pic_Name(Pic_num)
Pic_Name(Pic_num) = L_name
Pic_num = Pic_num + 1
L_name = Dir
Loop
Command1.Caption = "循環(huán)顯示圖片"
Command2.Caption = "隱藏圖片"
Picture1.AutoSize = True
Picture1.AutoRedraw = True
Picture1.Visible = False
Picture2.AutoSize = False
Picture2.AutoRedraw = True
Picture2.Visible = True
Timer1.Interval = 10
Timer1.Enabled = False
Timer2.Interval = 50
Timer2.Enabled = False
If Pic_num 0 Then
Picture1.Picture = LoadPicture(App.Path "\pic\" Pic_Name(L_id))
Picture2.PaintPicture Picture1.Picture, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight
Else
MsgBox ("沒(méi)有圖片顯示!")
End If
End Sub
Private Sub Timer1_Timer()
Dim L_id As Long
Randomize
L_id = Int(Pic_num * Rnd)
Picture1.Picture = LoadPicture(App.Path "\pic\" Pic_Name(L_id))
bili_w = Picture1.ScaleWidth / Picture2.ScaleWidth
bili_h = Picture1.ScaleHeight / Picture2.ScaleHeight
p_width = Picture2.Width / 100
p_height = Picture2.Height / 100
pic_star = 0
Timer1.Enabled = False
Timer2.Enabled = True
End Sub
Private Sub Timer2_Timer()
If pic_star 101 Then
pic_star = pic_star + 1
Picture2.PaintPicture Picture1.Picture, 0, 0, 100 * p_width, pic_star * p_height, 0, 0, bili_w * pic_star * p_width, bili_h * pic_star * p_height
Else
pic_star = 0
Timer1.Enabled = True
Timer2.Enabled = False
End If
End Sub