slide1 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
程式設計實習 PowerPoint Presentation
Download Presentation
程式設計實習

Loading in 2 Seconds...

play fullscreen
1 / 17

程式設計實習 - PowerPoint PPT Presentation


  • 151 Views
  • Uploaded on

程式設計實習. 繪圖-影像貼圖. 將圖檔載入到記憶體中並將此區域命名為 Bmp. 將圖檔載入 Bitmap 物件 ( 一 ). 方法一:宣告時同時載入圖檔. 語法:. Dim 物件名稱 As New Bitmap( “ 圖檔路徑 ” ). Dim Bmp As New Bitmap( “ C:\X.BMP ” ). 將圖檔載入 Bitmap 物件 ( 二 ). 方法二:先宣告 Bitmap 空間需要時再載入圖檔. 語法:. Dim 物件名稱 As Bitmap ……… 先宣告. Bitmap 名稱 =New Bitmap( 圖檔名 ) … 程式中再指定.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about '程式設計實習' - conlan


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide1

程式設計實習

繪圖-影像貼圖

bitmap

將圖檔載入到記憶體中並將此區域命名為Bmp

將圖檔載入Bitmap物件(一)

方法一:宣告時同時載入圖檔

語法:

Dim 物件名稱 As New Bitmap(“圖檔路徑”)

Dim Bmp As New Bitmap(“C:\X.BMP”)

bitmap1
將圖檔載入Bitmap物件(二)

方法二:先宣告Bitmap空間需要時再載入圖檔

語法:

Dim 物件名稱 As Bitmap ………先宣告

Bitmap名稱=New Bitmap(圖檔名)…程式中再指定

Dim BmpSrc As Bitmap

BmpSrc=New BitMap(“Src.Bmp”)

slide4
在畫布上貼圖

語法:

Graphics名稱.DrawImage(Bitmap名稱,x,y)

Dim DrawView As Graphics

.

.

DrawView=Graphics.FromImage(BmpView)

DrawView.DrawImage(BmpView,0,0)

slide5

記憶體繪圖區BmpSrc

圖檔

圖檔載入構想

步驟一:

以 Bmp名稱=New Bitmap(“檔名”)載入繪圖區

步驟二:

用DrawImage的方法將載入的圖形貼到工作區

記憶體繪圖區BmpView

步驟三:

將BmpView顯示在圖片盒上

記憶體

slide6

圖檔載入範例(一)

Dim BmpSrc,BmpView As Bitmap

Dim DrawView as Graphics

Private Sub Form_Load(ByVal…

BmpSrc=New Bitmap(“View.bmp”) ‘先將圖片載入記憶體

BmpView=New Bitmap(BmpSrc.Width,BmpSrc.Height) ‘指定目標畫布大小

DrawView=Graphics.FromImage(BmpView)‘將繪圖工具指定給畫布

End Sub

Private Sub Button1_Click(ByVal ….

DrawView.DrawImage(BmpSrc,0,0) ‘將來源圖片貼到畫布上

picView.Image=BmpView ‘將畫布顯示出來

End Sub

slide7

水平捲動軸

圖檔載入範例(二)-捲動

表單配置

水平捲動軸:

可用捲動的方式設定數值,主要常用的屬性為:

Maximum:設定最大值

Minimum:設定最小值

LargeChange:設定變動量

Value:捲軸值

slide8

圖檔載入範例(二)-捲動

Dim BmpSrc,BmpView As Bitmap

Dim DrawView as Graphics

Private Sub Form_Load(ByVal…

BmpSrc=New Bitmap(“View.bmp”) ‘先將圖片載入記憶體

BmpView=New Bitmap(BmpSrc.Width,BmpSrc.Height) ‘指定目標畫布大小

DrawView=Graphics.FromImage(BmpView)‘將繪圖工具指定給畫布

End Sub

Private Sub HScrollBar1_Scroll(ByVal …

Dim X As Integer

X=HScrollBar1.Value

DrawView.Clear(Color.White)

DrawView.DrawImage(BmpSrc,X,0) ‘將來源圖片貼到畫布的指定座標上

picView.Image=BmpView ‘將畫布顯示出來

End Sub

slide9

擷取影像-Clone

語法:

目的Bmp=來源Bmp.Clone(擷取範圍,影像格式)

擷取範圍:必需為一矩形(Rectangle)結構

Dim Cut As Rectangle

.

Cut=New Rectangle(X,Y,寬,高)

影像格式:需為像素資料,PixelFormat

slide10

擷取影像範例(一)

Dim BmpSrc,BmpView As Bitmap

Dim DrawViewas Graphics

Private Sub Form_Load(ByVal…

BmpSrc=New Bitmap(picSrc.Image)

BmpView=New Bitmap(picView.Width,picView.Height)

DrawView=Graphics.FromImage(BmpView)

End Sub

Private Sub Button1_Click(ByVal ….

DimBmpCut As Bitmap,Cut As Rectangle

Cut=New Rectangle(0,0,100,100) ‘設定擷取範圍

BmpCut=BmpSrc.Clone(Cut,BmpSrc.PixelFormat) ‘擷取

DrawView.Clear(Color.White) ‘清除畫布

DrawView.DrawImage(BmpCut,0,0) ‘將擷取的圖塊貼到畫布上

picView.Image=BmpView

End Sub

slide11

擷取影像範例(二)-亂數秀圖

將圖分割為八等份,並以Timer自動的一格一格的將圖秀出

(0,0)

(100,0)

(200,0)

(0,100)

(100,100)

原圖為400x200,因此每個分割單元為100x100

而貼圖時之座標則如圖上所示

slide12

擷取影像範例(二)-亂數秀圖

Dim ShowD As Integer

Dim G() As Integer={0,4,2,1,5,3,6,7} ‘設定顯示順序

Private Sub Button3_Click(ByVal …

DrawView.Clear(Color.White)

picView.Image = BmpView

ShowD=0

Timer1.Enabled = True

End Sub

Private Sub Timer1_Tick(ByVal …

Dim X,Y As Integer,BmpCut As Bitmap,Cut As Rectangle

X=(G(ShowD) Mod 4)*100:Y=(G(ShowD)\4)*100

Cut=New Rectangle(X,Y,100,100) ‘設定擷取範圍

BmpCut=BmpSrc.Clone(Cut,BmpSrc.PixelFormat) ‘擷取

DrawView.DrawImage(BmpCut,X,Y) ‘將擷取的圖塊貼到畫布上

picView.Image=BmpView

If ShowD = 7 Then’判斷圖顯示完了沒有

ShowD = 0 : Timer1.Enabled = False‘若指標等於8則圖已秀完,停止秀圖

Else

ShowD = ShowD + 1 ‘若不等於8則將指標調至下一個位置

End If

End Sub

slide13

(40,0)

(80,0)

(0,0)

(0,0)

擷取影像範例(三)-捲動

W1=400-40=360

W2=400-80=320

擷取貼上

擷取貼上

W2=320

W1=360

slide14

擷取影像範例(三)-捲動背景

Dim ScrollX As Integer

Private Sub Form1_Load(ByVal ...

ScrollX=0 ‘設定擷取起點變數

End Sub

Private Sub Button12_Click(ByVal sender...

Dim Cut As Rectangle‘設定擷取矩形區

Dim Bmp As Bitmap‘設定點陣圖區

DrawView.Clear(Color.White)‘清除畫布

Cut = New Rectangle(ScrollX, 0, 400 - ScrollX, 200)‘設定擷取來源圖塊範圍

Bmp = BmpSrc.Clone(Cut, BmpSrc.PixelFormat)‘擷取來源圖塊

DrawView.DrawImage(Bmp, 0, 0, 400 - ScrollX, 200)‘將擷取圖貼到畫布指定位置

ScrollX = ScrollX + 1‘設定捲動值

picView.Image = BmpView‘顯示畫布

End Sub

slide15

背景透明設定-MakeTransparent(色彩常數)

語法:

Bitmap物件.MakeTransparent(色彩常數)

色彩常數:是用來指定要去除的免彩,如:

Color.Black指的是將黑色設為透明

去背

slide16

背景透明程式範例

Private Sub Button9_Click(ByVal ...

Dim bmp as Bitmap

Bmp = Image.FromFile(“PAll.bmp”) ‘載入圖檔(做為前景用)

Bmp.MakeTransparent(Color.Black) ‘設定載入圖檔中要設為透明的顏色

DrawView.Clear(Color.White)

DrawView.DrawImage(BmpSrc, 0, 0) ‘將背景圖貼到畫布

DrawView.DrawImage(Bmp, 330, 100) ‘將前景圖也貼到畫布

picView.Image = BmpView ‘將畫布顯示在圖片盒上

End Sub

slide17

圖片切換範例

Dim BmpPig As Bitmap,Running As Integer

Private Sub Form1_Load(ByVal ...

BmpPig = New Bitmap("PAll.bmp") ‘載入圖檔(做為前景用)

BmpPig.MakeTransparent(Color.Black) ‘設定載入圖檔中要設為透明的顏色

Running = 0

End Sub

Private Sub Button10_Click(ByVal ...

Dim bmp as Bitmap, Cut as Rectangle

DrawView.Clear(Color.White)

Cut = New Rectangle(0, Running * 64, 64, 64) ‘設定擷取來源圖塊範圍

Bmp = BmpPig.Clone(Cut, BmpPig.PixelFormat) ‘擷取來源圖塊

DrawView.DrawImage(BmpSrc, 0, 0) ‘將背景圖貼到畫布

DrawView.DrawImage(Bmp, 300, 120) ‘將前景圖也貼到畫布

Running = IIf(Running = 2, 1, 2) ‘調整動作擷取變數

picView.Image = BmpView ‘將畫布顯示在圖片盒上

End Sub