12

1,137 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,137
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

12

  1. 1. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ XII Á¯ËÝà GRAPHICS ÁÀ MULTIMEDIA ÏÐÎÃÐÀÌ×ËÀË • Õÿëáàð çàìààð Graphics õèéõ; • Device context and Tcanvas; • GDI îáüåêòóóä o Pens, Brushes, Fonts; o Bitmaps áà Palette; o Region îãòëîõ; o Teêñò çóðàõ; o Bitmap çóðàõ; o Memory Bitmap ¿¿ñãýõ; o Memory Bitmap –èéã õàäãàëàõ; • Multimedia ïðîãðàì÷ëàõ o Windows API aøèãëàí Wave Audio òîãëóóëàõ; o TmediaPlayer êîìïîíåíò; o MediaPlayer Properties , Methods áà Events o Wave Audio o Ãàðàëòûí volume –ã òîõèðóóëàõ; o Wave Audio –ã áè÷èæ àâàõ; • MIDI Audio; • CD Audio; • AVI Video; Graphics and Multimedia íü ïðîãðàìûí äýýä ò¿âøíèéã òºëººëäºã. ªíººäðèéí ýíý ñýäýâò òà íàð Graphics áà Multimedia –ã Delphi õýë äýýð ïðîãðàì÷ëàõ òóõàé ¿çýæ òàíèëöàíà. Graphics –èéã ïðîãðàì÷ëàõûí òóëä ÿìàð ÷ ãýñýí TCanvas TBitmap êëàññóóäûí òóõàé íèëýýä õýäýí ç¿éëèéã ìýäýõ õýðýãòýé. Áè òà íàðò Delphi õýë äýýð Graphics –ã ¿ç¿¿ëýõ õÿëáàð àðãààñ ýõýëüå. ¯¿íèé äàðàà òà íàð Windows Graphics Device Interface (GDI)–èéí òóõàé ìºí ò¿¿íèé êîìïîíåíòóóäûíõ òóõàé ìýäýæ, õèéæ ñóðíà. Îäîî áèä îëîí òºðëèéí õ¿ðýý, õýëáýð ä¿ðñ çóðàõ òîãòñîí äýã æóðìûí òóõàé ìºí Bitmap ¿ç¿¿ëýõ îëîí àðãûã ñóðíà. Õàðèí Multimedia Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  2. 2. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ ïðîãðàì÷ëàõ á¿ëãèéí õýñýãò õýðõýí Windows API -ààð äóóò ôàéë òîãëóóëàõ òóõàé ¿çíý. ̺í òà íàð äîëãèîíò Audio òîãëóóëàõ, MIDI áîëîí AVI video òîãëóóëàõàä TMediaPlayer êëàññ õýðõýí õýðýãëýãäýõ òóõàé ñóð÷ ìýäýõ áîëíî. Èéìýýñ ýõýëöãýýå. TextRect Clipping rectangle äîòîð òåêñò áè÷èõ Ýäãýýð properties áà methods íü Windows Device context –èéí ¿¿ðãèéí áàãà õýñãèéã òºëººëäºã. Ãýõäýý òà íàðò õýëýõýä Graphics -òàé àæèëëàæ áàéõàä ýäãýýð properties áà methods 80 õóâèéí ¿¿ðãèéã ã¿éöýòãýäýã. Õýäèéãýýð èéì áîëîâ÷ áè TCanvas –èéí òóõàé ÿðèõààñàà ºìíº Graphic’s object –èéã ÿàæ Windows ïðîãðàì÷ëàëä õýðýãëýõ òóõàé ÿðèõ õýðýãòýé áîëîâ óó. GDI objects GDI –ä îëîí òºðëèéí îáüåêòóóä áàéäàã áà ýäãýýð íü õýðõýí device context ôóíêöèéã òîäîðõîéëäîã áîë? GDI –èéí ýíãèéí õýðýãëýãääýã îáüåêòóóä íü Pens, Brushes, Fonts. Áóñàä îáüåêòóóäàä Palettes, Bitmaps, regions áàãòäàã. Ýõëýýä Pens, Brushes, Fonts –èéã ¿çýýä äàðàà íü complex object -ðóó îðöãîî¸. Pens, Brushes, áà Fonts Pens, Brushes, Fonts íü TCanvas êëàññò ÿàæ õýðýãëýãäýæ áàéãààã àâ÷ ¿çüå. Pens Pen íü îáüåêòîîð òîäîðõîéëîãäñîí áà øóãàì çóðàõàä õýðýãëýãäýíý. Øóãàì íü øóëóóí áàéõ áà íýã öýãýýñ ýõëýëòýé íýã öýãò òºãñãºëòýé ýñâýë òýãø ºíöºãò, ýëëèïñ, îëîí ºíöºãòèéí õ¿ðýý áàéíà. TCanvas êëàññûí Pen property –ààð pen –ýý îðóóëàõ áà ýíý íü TPen êëàññûí æèøýý þì. Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  3. 3. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ Õ¿ñíýãò 12.3 TPen-èéí property- íóóäûã æàãñààâ. Property Òàéëáàð Color Line -èéíõàà ºíãèéã çààæ ºãíº. Handle Pen –èéí handle (HPEN) GDI øóóä äóóäàãäàõ ¿åä Mode Line ÿàæ çóðàãäàõûã òîäîðõîéëæ ºãíº. (normal, inverse, xor..) Style Pen -èéí style. Solid, Dashed, Dash-dot, Clear ãýõ ìýò. Width Pen -èéí ºðãºíèéã òîäîðõîéëíî. Õ¿ñíýãò 12.3 TPen properties. Ýäãýýð øèíæ ÷àíàðóóäûã òà õ¿ññýíýýðýý òîõèðóóëíà. Äîîðõ æèøýýíä óëààí ºí㺺ð Dashed line-ð õàðóóëàâ. Canvas.Pen.Color:=clRed; Canvas.Pen.Style:=psDash; Canvas.MoveTo(20,20); Canvas.LineTo(120,20); Ýíý êîä÷èëîëûã ôîðìûíõàà òîâ÷èíä OnClick handler äýýð òóðøèæ ¿çýýðýé. Òàíûã òîâ÷èí äýýðýý äàðàõàä çóðàãäàõ øóëóóí íü form äýýð ãàðàõ áîëíî. Òýìäýãëýë : Ýíý ñýäâèéí á¿õ æèøýýí¿¿äèéã èéì áàéäëààð òóðøèæ ¿çñýí áàéõ õýðýãòýé. Õýðýâ òà íàð äýýðõ æèøýýã òóðøèæ ¿çñýí áîë form –îî äýýø íü 纺õºä òàíû çóðñàí øóëóóí àðèëàõ áîëíî. Èéìýýñ ¿¿íèéã áàéíãûí áîëãîõûã õ¿ñâýë form –èéí OnPaint event –ä äýýð øóëóóí çóðäàã êîäîî áè÷èæ áîëíî. OnPaint event íü form –èéí õàðàãäàõ áàéäàë, áàéðøèë ººð÷ëºãäõºä ¿¿ñýýäýã. Dashed áà Dotted pen style çºâõºí pen width –èéí óòãà 1 áàéõ ¿åä õýðýãëýãäýíý. PsClear pen style íü line –àà óñòãàõàä õýðýãëýãäýíý. Òýãýõäýý ýíý line íü Windows GDI draw –èéí îáüåêò áîëîõ òýãø ºíöºãò, ýëëèïñ, îëîí ºíöºãò¿¿äèéí ýðãýí òîéðíû õ¿ðýýã õýëæ áàéãàà þì. Ǻâëºìæ: TPen –èéí îëîí property -íóóäûã form äýýðýý Shape component àøèãëàí òóðøèæ ¿çýýðýé. ̺í Shape –èéíõàà pen -èéí Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  4. 4. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ property –ã ººð÷èëæ ñàéæðóóëààðàé. TPen êëàññûí Mode øèíæ ÷àíàð íü effect -¿¿äèéí ãàäíàõ õàðàãäàõ áàéäàëä îíöãîé õýðýãòýé áàéäàã. Brushes Ýíý íü Graphical Shape -èéí äîòðîõ õýñãèéã áóþó filled area –ã òºëººëäºã. Õýðâýý òà íàð ýëëèïñ, òýãø ºíöºãò, îëîí ºíöºãò¿¿äèéã çóðñàí áîë Brush -ã àøèãëàí ä¿¿ðãýæ áîëíî. Èõýâ÷ëýí ýíý ¿åä Brush íü çºâõºí ºí㺠áàéäàãã¿é Bitmap ýñâýë pattern –èéã àãóóëñàí áàéäàã. Brush íü TCanvas class -ä áàéäàã áà íýã property þì. Brush –ààð õàðàãäàõ õýëáýðèéã ººð÷èëæ òóðøèæ ¿çýýðýé. Brush íü Tbrush class -èéí íýã îáúåêò þì. TPen, TBrush class -ä áè÷èæ òýìäýãëýõ event, method åðººñºº áàéäàãã¿é. Õ¿ñíýãò 12.4 –ò øèíæ ÷àíàðóóäûã æàãñààæ áè÷èâ. Property Òàéëáàð Bitmap Brush –èéí background –ä õýðýãëýãäýíý. Color Brush -èéí ºíãèéã òîõèðóóëíà. Handle Brush –ä àâàõ óòãà: HBRUSH. GDI -èéí ¿åä õýðýãëýãäýíý. Style Brush –èéí style. ¯¿íä: solid, clear ýñâýë íèëýýä õýäýýñ íýãèéã íü ñîíãîõ (bsHorinzontal, bsVertical, bsEDiagonal, bsBDiagonal, bsCross). Áèåë¿¿ëýõäýý: õýðâýý ä¿¿ðãýõ áîë Style property äýýð bsSolid ãýæ òàâèõ. Õ¿ñíýãò12.4 TPen properties. Äîîðõ æèøýýíä ôîðì äýýðýý äóãóé çóðààä 45 ãðàäóñûí íàëóóòàé çóðààñààð äîòðîõûã íü áóäàõ õýëáýðèéã àøèãëàëàà. Canvas.Brush.Color:=clBlue; Canvas.Brush.Style:=bsDiagCross; Canvas.Ellipse(20,20,220,220); Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  5. 5. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ Brush -èéí õýâ ìàÿãèéã àøèãëàæ áàéõàä ò¿¿íèé Color property øóãìûí ºíãèéã ººð÷èëäºã áà ýíý øóãàì íü çóðãèéíõ þì. Çàðèì íýã VCL automatically forces çýðýãò background mode -èéã transparent áîëãîäîã. Ãýõäýý ýíý íü pattern fill ¿åä áîëíî. Background mode –èéã transparent áîëãîíî ãýäýã íü ä¿ðñèéí äýâñãýðèéã öîíõíû äýâñãýð ºíãº, õýâ ìàÿã õýëáýðòýé àäèë áîëãîõûã õýëæ áàéãàà þì. ªìíºõººñ àðàé ººðººð õàðàãäóóëúÿ. ªºðººð õýëáýë äóãóé ä¿ðñèéí äýâñãýð ºíãèéã ôîðìûíõòàé àäèë áîëãîæ . Ýíèéã grayscale -äýýð õàðàõ òèéì àìàð áèø ãýäãèéã ìýäýæ áàéíà. Õýðýâ background –àà òóñ òóñä íü òîäîðõîéëîõûã õ¿ñâýë VCL circumvent õýðýãòýé áà API –ðóó øóóä î÷íî. Ýíä õýðýâ öàãààí äýâñãýð äýýð õºõººð çóðààñ òàòàõ êîäûã ¿ç¿¿ëýâ : Canvas.Brush.Color:=clBlue; Canvas.Brush.Style :=bsdiagCross; SetBkMode(Canvas.handle,OPAQUE); SetBkColor(Canvas.Handle, clWhite); Canvas.Ellipse(20,20,220,220); Îäîî äýâñãýð ºí㺠öàãààí áîëîõûã Figure12.2 ò äýýðõ êîä÷èëîëîîð äóãóé ä¿ðñèéã õàðóóëàâ. Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  6. 6. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ Brush -èéí ººð ñîíèðõîëòîé ºâºðìºö îíöëîã íü Bitmap background option þì. Äîîð áè÷èãäýõ êîä÷èëîë íü bitmap brush -èéí òóõàé èõ ç¿éëèéã õýëæ ºãíº: Canvas.Brush.Bitmap:=TBitmap.Greate; Canvas.Brush.Bitmap.LoadFromFile(‘bkgnd.bmp’); Canvas.Ellipse(20,20,220,220); Canvas.brush.Bitmap.Free; Ýõíèé ìºðºíä TBitmap îáüåêòèéí ¿¿ñýæ áóéã Brush -èéí Bitmap property –ðóó ãýæ òîäîðõîéëæ áàéíà. Bitmap property íü óòãàà àâààã¿é ¿¿ñýæ áàéãàà ìàø ºâºðìºö áàéíà. Õî¸ð äàõ ìºðºíä bitmap -àà ôàéëààñ 纺æ áàéíà. Ãóðàâ äàõ ìºðºíä ýëëèïñ çóðæ áàéíà. Ýíý ìºðíèé äàðàà ýëëèïñ çóðàãäñàí áàéõ ó÷ðààñ Brush property óñòãàãäàæ áàéíà. Ýíý ¿éëäýë çàéëøã¿é ÷óõàë þì. Ó÷èð íü VCL òàíä ¿¿íèéã õèéæ ºãºõã¿é. Õýðâýý brush property óñòãàõ íü á¿òýëã¿é áîëáîë òàíû ïðîãðàìä ñàíàõ îé õ¿ðýõã¿é áîëîõ ìàãàäëàëòàé. Äîîðõ çóðàãò Bitmap brush -ààð ýëëèïñ çóðñíûã õàðóóëàâ. Òàíä çàðèì ¿åä çààâàë hollow Brush õýðýã áîëíî. ¯¿ãýýð background -àà õàðóóëàõ áîëíî. Hollow Brush -àà ¿¿ñãýýä ò¿¿íèéõýý brush style ä çºâõºí bsClear ãýæ ºãíº. Îäîî á¿ãäýýðýý ºìíºõ æèøýýãýý àâ÷ ò¿¿í äýýðýý 2 äàõü äóãóéãàà äîòîð íü íýìæ hollow brush aøèãëàÿ. Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  7. 7. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ procedure TForm1.Button1Click(Sender: TObject); begin Canvas.Pen.Width:=1; Canvas.Brush.Bitmap:=TBitmap.Create; Canvas.Brush.Bitmap.LoadFromFile('bkgnd.bmp'); Canvas.Ellipse(20,20,220,220); Canvas.Brush.Style:=bsClear; Canvas.Pen.Width:=5; Canvas.Ellipse(70,70,170,170); Canvas.brush.Bitmap.Free; end; Õýðâýý øóóä API ðóó î÷âîë òà ººð ç¿éë¿¿äèéã õèéõ áîëîìæòîé áîëíî. Õýäèéãýýð èéì áîëîâ÷ VCL Brush class –ò èõýâ÷ëýí ýäãýýðèéã ã¿éöýòãýäýã. Fonts Ýíä ÿìàð íýãýí øèíý ç¿éë áàéõã¿é. Fonts íü TCanvas class –òàé õýðýãëýäýã áà Tcanvas -èéí Fonts -îîñ ÿëãààã¿é ôîðì ýñâýë áóñàä êîìïîíåíòóóäàä õýðýãëýãääýã. TCanvas –èéí Font property íü áóñàä êîìïîíåíòóóäûí Font property -òàé èæèë áàéäàã. Canvas -ò font -èéã ñîëèõäîî çºâõºí ¿¿íèéã õèéãäýã: Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  8. 8. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ Canvas.Font.Name:=’Courlier New’; Canvas.Font.Size:=14; Canvas.Font.Style:=Canvas.Font.Style+[fsBold]; Canvas.TextOut(20,20, ‘ Testing’); Áàéíà. Äàðàà áèä òåêñò çóðàõ õýñýã äýõ fonts íü þó õèéäýã áîëîõûã àâ÷ ¿çüå. Bitmaps áà Palette Èõýíõäýý bitmaps, palettes –óóä íü õàìòäàà ÿâäàã. TBitmap class -èéã õýðýãëýæ áàéõ ¿åä Bitmap à÷ààëàõ áà ä¿ðñëýë õèéõýä õÿëáàð áàéäàã. Òà íàð õýäèéíýý VIII á¿ëýãèéí õè÷ýýë äýýð Jumping Jack ïðîãðàì äàõü TBitmap –èéí ¿éë àæèëëàãààã õàðñàí. TBitmap class íýëýýä õýä õýäýí íºõöºë áàéäàëä ºðãºí õýðýãëýãääýã. Äàðààãèéí á¿ëýãò bitmaps çóðàõ áîëîí Memory Bitmaps –èéí òàëààð ÿðèõ ¿åä çàðèì íºõöºë áàéäëûã õàðàõ áîëíî. TBitmap class íü íýã öîãö ó÷ðààñ áè method, property á¿ðèéã òàéëáàðëààã¿é áîëíî. Palette –èéí ÷óõàë à÷ õîëáîãäëûã òàéëáàðëàõààð æèøýý àâ÷ ¿ç¿¿ëëýý. OnPaint event handler äýýð êîä÷èëîëûã ýñâýë button click event äýýð õýðýãëý. procedure TForm1.Button1Click(Sender: TObject); Var Bitmap :TBitmap; begin Bitmap:=Tbitmap.Create; { Bitmap.IgnorePalette:=True;} Bitmap.LoadFromFile('c:co.bmp'); Canvas.Draw(0,0,Bitmap); Bitmap.Free; End; Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  9. 9. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ Ïðîãðàì àæèëëóóëàõàä òà ãî¸ Bitmap –èéã ôîðìààñàà õàðàõ áîëíî. Ýäãýýð ìºðí¿¿ä îéëãîìæòîé òóë òàéëáàðã¿é. Õàðèí 4 äàõ ìºðºíä VCL –èéí Palette -èéí ìýäýýëëèéã òàòãàëçààðàé. Òýãýýä äàõèí ïðîãðàìàà àæèëëóóëààðàé. Èíãýõýä bitmap-èéí ºí㺠á¿ãä áóðóó õóäàë áîëíî. (õýðâýý video adapter –èéíõàà display –èéã more than 256 Colors ãýæ òîõèðóóëáàë òà ýíý ¿ð íºëººã àíçààð÷ ÷àäàõã¿é. ) ßàãààä ãýâýë palette aøèãëàæ ÷àäàõã¿é. Õàðèí palette bitmap -èéíõàà çºâ ºíãºí¿¿äèéã palette system -ä íàéäâàðòàé õóâèàðëàæ ÷àääàã. Bitmap, Palette îáüåêòóóä íü Graphics áîëîâñðóóëàëòàä ÷óõàë ¿¿ðýãòýé îðîëöäîã áàéíà. Clipping Regions Regions íü Canvas –èéí äýëãýöýíä çóðàõ õýñãèéã õÿíàæ áàéäàã ìóæ þì. TCanvas class –ä ClipRect property áàéäàã. Õàðèí ýíý íü çºâõºí óíøäàã. Clipping Regions-èéã ººð÷ëºõºä Windows API –ã õýðýãëýõ õýðýãòýé. Îäîî ºìíºõ æèøýýãýý àâ÷ õýðõýí Clipping Regions work –ä áàãà çýðýã çóðàã õàâñàðãàæ ò¿¿íèéãýý ººð÷èëæ ñàéæðóóëàõûã ¿çüå. procedure TForm1.Button1Click(Sender: TObject); Var Bitmap: TBitmap; Rgn: HRGN; Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  10. 10. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ begin Bitmap:=Tbitmap.Create; Bitmap.LoadFromFile('c:co.bmp'); Rgn:=CreateRectRgn(100,50,250,250); SelectClipRgn(Canvas.Handle ,Rgn); Canvas.Draw(0,0,Bitmap); Bitmap.Free; End; Îäîî ïðîãðàìàà àæèëëóóëàõàä òà çºâõºí Bitmap -èéí õàðàãäàæ áàéãàà õýìæýýã õàðàõ áîëíî. SelectClipRgn ôóíêö íü Canvas Clipping Region (õàé÷ëàõ ìóæ) –èéã òýãø ºíöºãòòýé àäèëòãàæ êîîðäèíàòûã 100,50,250,250 ãýæ òîãòîîäîã. ªìíº íü bitmap -èéã õºäºë㺺íã¿é áàéðëàëä çóðñàí áîë îäîî çºâõºí Bitmap -èéí Clipping Region –îîð õýìæýýã íü òîäîðõîéëñîí íü õàðàãäàæ áàéíà. Clipping Region –ààñ ãàäíàõûã ýñ çºâøººðñºí áàéíà. ªìíºõ æèøýýãýý àâ÷ îëîí ñîíèðõîëòîé ç¿éë õèéæ ººð÷èë뺺. Òýãø ºíöºãò Region ¿¿ñãýæ áàéãàà ìºðèéã àâ÷ îðîíä íü äîîðõ ìºðèéã òàâèëàà. Rgn:=CreateEllipticRgn(30,30,170,170); Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  11. 11. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ Îäîî äàõèí ïðîãðàìàà à÷ààëëààðàé. Ýíý ¿åä Bitmap circular region - ààð õÿçãààðëàãäàíà. Çà îäîî region –íèé ººð íýã òºðëèéã àâúÿ: Const Points: array [0..3] of Point = ((X:80,Y:0) ,(X:0,Y:80), (X:80,Y:160), (X:160,Y:80)); Var Bitmap: TBitmap; Rgn: HRGN; begin Bitmap:=Tbitmap.Create; Bitmap.LoadFromFile(‘c:co.bmp’); Rgn:=CreatePolygonRgn(Points,4,ALTERNATE); SelectClipRgn(Canvas.Handle ,Rgn); Canvas.Draw(0,0,Bitmap); Bitmap.Free; End Ýíý ¿åä òà îëîí ºíöºãòèéí region õýðýãëýæ region ¿¿ñãýæ áóé öýã¿¿äýýð ìàññèâ òîäîðõîéëíñîí áàéíà. CreatePolygonRgn ôóíêö íü öýã¿¿äèéí Region form öóâààã ¿¿ñãýæ áàéíà. ¯¿í øèã õ¿ññýíýýðýý îëîí öýã¿¿äèéã Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  12. 12. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ õýðýãëýæ áîëíî. Òºãñãºëèéíõ íü õààãäàõ öýãèéã îíöãîéëîí çààæ áîëîõã¿é ó÷èð íü region àâòîìàòàà𠺺𺺠ýõëýëèéí öýã òºãñãºëèéí öýãèéã õîîðîíä íü õîëáîæ òºãñãºäºã. Äàõèí ïðîãðàìàà àæèëëóóëæ ÿìàð ¿ð ä¿í ºãºõèéã õàð. Òýìäýãëýë: Ýíä áè÷ñýí êîä÷èëîëûí õýñýãò õýðõýí ìàññèâûí àíõíû óòãûã òîãòîîõûã õàðóóëàâ. Êîä÷èëîë: Const Points: array [0..3] of Point =((X:80,Y:0),(X:0,Y:80),(X:80,Y:160),(X:160,Y:80)); Ýíä Tpoint ìàññèâûí õÿçãààðûã òîãòîîæ àíõíû ºãºãä뺺ð õàíãàæ áàéíà. Tpoint –ä 2 òàëáàð áàéäàã. X áà Y ãýñýí. ¿¿íä fieldname áóþó òàëáàðûí íýðèéã æàãñààæ òîäîðõîéëîõ öýãýýð ºãºãäëèéã íü òîãòîîæ ºãºõ . Æèøýý íü: (X:80) ̺í X áà Y-èéí ºãºãä뺺ð õàíãàãäñàí áèåèéã õîñ õîñîîð íü íèéë¿¿ëæ áè÷íý. ¯¿íèéã 4 óäàà áè÷ñýí. ßàãààä ãýâýë ìàññèâò 4 ýëåìåíò áàéíà. Ìàññèâûã çàðëàæ àíõíû óòãà òîãòîîõäîî çºâõºí èéì áàéäëààð áè÷íý. Òà region –èéã äàíäàà õýðýãëýõã¿é ÷ ãýñýí òàíä õýðýãòýé ¿åä ¿íýëæ áàðøã¿é ÷óõàë áîëíî. Çóðàã áîëîâñðóóëàëòàíä øààðäëàãàòàé ç¿éë¿¿äèéã õèéæ ã¿éöýòãýõýä õýðýã áîëíî. Çóðàõ ¿íäñýí àæèëëàãàà ªìíº íü òà íîìíîîñ ãðàôèêèéí çàðèì ¿íäñýí õýâ ìàÿãòàé òóëãàð÷ áàéñàí áàéõ. ¯¿ãýýðýý òà Rectangle method íü òàëáàé áà òýãø ºíöºãò çóðàõàä õýðýãëýãääýã ãýäãèéã, õàðèí Ellipse method íü äóãóé áà çóéâàí ä¿ðñ çóðàõàä, MoveTo áà LineTo -ýýð õ¿ðýý çóðàõäàà õýðýãëýäãèéã ìýäñýí áàéãàà áàéõ. ̺í Arc method íóì çóðàõàä, Pie method pie-shaped objects çóðàõàä õýðýãëýãääýã. Ýíý á¿ãä ÷óõàìäàà ¿íäñýí îéëãîëòóóä þì. Teêñò çóðàõ Drawing text õèéæ ñóðàõ íü õýö¿¿ äàäëàãà þì. Íýìæ õýëýõýä ¿¿íä íèëýýä õýäýí ãî¸ ºâºðìºö îíöëîãóóä áàéäàã . Ýäãýýðèéí òàëààð òà íàð ìýäýæ àâàõ õýðýãòýé . Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  13. 13. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ TextOut áà TextRect ôóíêöóóä TextOut method canvas äýýð áè÷èõ ¿íäñýí àðãà áîëæ ºãäºã. ¯¿íä òèéì ÷ õýö¿¿ þì áàéõã¿é. Òà íàð çºâõºí X áà Y –èéíõàà áàéðëàëûã çààæ ºã÷ õàðàãäàõ òåêñòýý æèøýýí äýýðõòýé èæèë áè÷èæ ºãíº: procedure TForm1.Button1Click(Sender: TObject); begin Canvas.TextOut(20,20, 'www.csms.edu.mn/cheri'); End; Ýíý íü ôîðìûí string –èéã 20,20 áàéðëàëä ãàðãàíà. X áà Yíü ãàðàõ òåêñòèéíõýý ç¿¿í äýýä áóëàíãààñ íü áàéðëóóëäàã. ¯¿íèéã òóðøèæ ¿çýýðýé. procedure TForm1.Button1Click(Sender: TObject); begin Canvas.TextOut(20,20, 'www.csms.edu.mn/cheri'); Canvas.MoveTo(20,20); Canvas.LineTo(100,20); End; Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  14. 14. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ Ýíý êîä÷èëîë òåêñòýý 20, 20 áàéðëàëä ¿ç¿¿ëæ, ìºí øóãàì 100, 20 õ¿ðòýë çóðæ áàéíà. Øóãàì íü òåêñòèéíõàà îðîéíîîñ õºíäëºí㺺ð çóðàãäñàí. TextRect method íü òàíä clipping rectangle -äýý òåêñò íýìæ õàðóóëàõ áîëîìæèéã îëãîäîã. Ýíý method -èéã õýðýãëýæ áàéõ ¿åäýý òåêñòýý çààâàë òîäîðõîé õèë õÿçãààð äîòîð íü áàãòààõ õýðýãòýé. Õýðýâ õÿçãààðààñ èë¿¿ ãàðàõ þì áîë õàé÷èëäàã. Äîîðõ æèøýýíä 100 -ààñ èë¿¿ ãàðñíûã ¿ç¿¿ëæ áàòàëæ áàéíà. Ǻâëºãºº: Õýðýâ òåêñòýý tab òºãñãºëòýé áè÷âýë Windows API ôóíêö TabbedTextOut-ã õàðààðàé. TextBackground Ñààðàë ôîðì äýýð öàãààí background –òàé áàéñàí íü ñýòãýë òàòàõã¿é áàéíà. Text background -èéã öàãààíààð òîãòîîñîí brush -ààñ îëæ àâñàí. Óã àñóóäëûã øèéäýõ 2 àðãà çàì áàéíà. Ýõíèéõ íü canvas brush -èéí ºíãèéã ñîëèõ, äàðààãèéíõ íü text background –ã transparent õèéõ. Text background – èéã ººð÷ëºõ íü õÿëáàð áàéíà. Òýãýõäýý íýã àñóóëò áàéíà. ßìàð ºí㺺ð òåêñòèéíõàà äýâñãýð ºíãèéã áîëãîõîî ìýäýæ áàéíà óó? Ýíý íºõöºëä òåêñòèéíõàà äýâñãýð ºíãèéã ôîðìûíõòàé èæèë áîëãîâ. ¯¿íèé òóëä: Canvas.Brush.Color:=Color; Ãýæ õèéíý. Ýíý êîä÷èëîë íü îëîí íºõöºë áàéäàëä àæèëëàíà. Çàðèì ¿åä òàíä îëîí êîíòðîë áàéíà. Õàðèí òà çºâõºí text transparent -èéíõàà Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  15. 15. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ background -èéã ººð÷ëºõ þì áîë õÿëáàð áîëíî. Êîä÷èëîë íü ÿìàð áàéõûã õàðóóëúÿ: Var OldStyle: TbrushStyle; Begin OldStyle:=Canvas.Brush.Style; Canvas.Brush.Style:=bsClear; Canvas.textOut(20,20, ‘www.csms.edu.mn/cheri’); Canvas.brush.Style:=OldStyle; End Ýõëýýä îäîîãèéí áàéãàà brush style -àà õàäãàëíà. Äàðàà íü brush style -èéã transparent äýýð bsClear ãýæ òîãòîîæ ºãíº. Òýãýýä òåêñòýý õàðóóëñíûõàà äàðàà Brush style -èéã ýðãýýä óðä íü ÿìàð ñòèëü áàéñíûã òàâèëàà. Òà òåêñòýý áè÷èæ ºã÷èõººä ºìíºõ style -àà õàäãàëñàí õýëáýðýýð íü äàõèí òîãòîîæ ºãíº. Ýíý íü õóó÷èí áàéñàí brush style -èéã öààøèä áàéõ íü ç¿ãýýð ãýæ áîäâîë äàõèí òîãòîîæ áîëîõûã õàðóóëàâ. Transparent background õýðýãëýõ ¿åä áàñ íýã ººð äàâóó òàë áèé. Ýíý íü òà õýñýã òåêñòýý bitmap background äýýð ãàðãàõ áîëîìæòîé áîëëîî ãýñýí ¿ã. Õàðèí ýíý ¿åä solid äýâñãýð õýðýãëýæ áîëîõã¿é. Êîä÷èëîë íü çóðãèéí õàìò (factory.bmp file íü Borland Shared Files 56 Color äèðåêòîîðîîð îëäîíî.) procedure TForm1.Button1Click(Sender: TObject); Var OldStyle: TbrushStyle; Bitmap:TBitmap; Begin Bitmap:=Tbitmap.Create; Bitmap.LoadFromFile(‘factory.bmp’); Canvas.Draw(0,0, Bitmap); Canvas.Font.Name:=’Arial Bold’; Canvas.Font.Size:=13; Oldstyle:=Canvas.Brush.Style; Canvas.Brush.Style:=bsClear; Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  16. 16. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ Canvas.TextOut(20,5,’Transparent background’); Canvas.brush.Style:=OldStyle; Canvas.TextOut(20,30,’solid background’); Bitmap.Free; end; Ýíý êîä íü ôîðì äýýð bitmap çóðíà. Äàðàà íü òåêñò ôîðìä çóðàã íü äýýð transparent background –ààð áè÷èãäýíý. ¯ð ä¿íã õàðæ áàéõàä background transparent íü òàíä òààëàãäàíà. ̺í transparent background òåêñòýíä çóðàã õàâñàðãàíà. ¯¿íèéã óã íîìíû XIII á¿ëýãò “Owner Drawn Status panels” õýñýãò ¿çíý. Draw Text ôóíêö Windows API DrawText ôóíêö íü canvas äýýð TextOut -ààñ èë¿¿ ºðãºí áîëîìæòîé þì. TCanvas class -ä DrawText method áàéäàãã¿é ó÷ðààñ DrawText –èéã õýðýãëýõäýý øóóä äóóäíà. Ýõëýýä DrawText -èéí æèøýýã õàðààä äàðàà íü ýíý ôóíêöûí òóõàé àâ÷ ¿çüå. Var R:TRect; begin R:=Rect(20,20,280,80); Canvas.Rectangle(20,20,280,80); DrawText(Canvas.Handle,’An example of drawetext.’,- Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  17. 17. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ 1,R,DT_SINGLELINE or DT_VCENTER DT_CENTER); end; Ýõëýýä Rect -èéã windows API Rect ôóíêöààð àíõíû óòãà òîãòîîñîîí áàéíà. ¯¿íèé äàðààõ ìºð íü Canvas äýýð rectangle áóþó òýãø ºíöºãòèéã çóðæ áàéíà. Èíãýõäýý òýãø ºíöºãòèéí ò¿¿í äýýð çóðàãäàõ õýìæýýã íü çààæ ºãíº. Ñ¿¿ëèéí ìºðºíä òåêñò áè÷èõäýý Drawtext ôóíêöûã äóóäàí áè÷èæ áàéíà. Õàðèí îäîî ýíý ôóíêöûíõýý õîîðîíäîî ÿëãààòàé ïàðàìåòð¿¿äèéã íü àâ÷ ¿çüå. • Ýõíèé ïàðàìåòð íü òóõàéí çóðãàà áóþó æèøýýí äýýðõ òýãø ºíöºãòºº þóí äýýð çóðàõàà çààæ ºãíº. • Õî¸ðäàõ ïàðàìåòðò string óòãà àâ÷ õàðàãäàõ òåêñòýý áè÷èæ ºãíº. • Ãóðàâäàõ ïàðàìåòðò çóðàãäàõ õýñãèéíõ òîîã çààæ ºãíº. –1 óòãàòàé áàéâàë ýíý íü string-èéã á¿òýíýýð íü ãàðãàíà. • Drawtext -èéí 4 äºõ ïàðàìåòð TRect õóâüñàã÷èéã àâíà. ßàãààä ãýâýë çàðèì Drawtext -èéí áîëîâñðóóëàëò òýãø ºíöºãòèéã õèéõäýý ººð÷èëäºã ó÷èðààñ ýíý ïàðàìåòð õóâüñàã÷ àâíà. • DrawText õýðõýí àæèëëàõûã ýíý ïàðàìåòðò áè÷íý. Ïàðàìåòð íü òåêñòýý áè÷èõ ¿åä õýðýãëýãäýõ flag-èéã çààíà. Ýíý æèøýýíä DT_SINGLELINE, DT_VCENTER, DT_CENTER flag-èéã õýðýãëýñýí áàéíà. Ýíý flags íü òåêñòèéã äàí øóãàìààð, õºíäëºí㺺ð íü ãîëëóóëæ ãàðãàõûã èëýðõèéëæ áàéãàà þì. Drawtext -ä áàðàã 20 flags áàéäàã áà òýäãýýðèéã òóñ òóñä íü òîäîðõîéëæ áîëíî. Áè òýð áîëãîíûã òàéëáàðëàìààðã¿é áàéíà ó÷èð íü Win 32 API –èéí online help -ä ã¿éöýò æàãñààæ áè÷ñýí áàéäàã . ªìíºõ æèøýýíäýý Drawtext ôóíêöäýý òåêñòýý ãîëëóóëæ Horizontally, Vertically, both çýðãýýñ íýãèéã íü ñîíãîí àâñàí. Òà ÿã îäîî ýíý ôóíêöûí à÷ õîëáîãäëûã óõààðàõã¿é áàéæ ìàãàäã¿é. Ãýâ÷ òà õýðâýý owner drawn components õèéæ ýõëýõýýð ýñâýë own graphical compoment -aa áè÷èæ ýõëýõýýðýý õýðýãöýýã íü ìýäðýõ áîëíî. procedure TForm1.Button1Click(Sender: TObject); Var Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  18. 18. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ R: TRect; begin R:=Rect(20,100,120,150); DrawText(Canvas.Handle,'This text is too long.',-1, R, DT_END_ELLIPSIS); end; Äýýðõ êîä àæèëëàõàä ¿¿ñýõ ¿ð ä¿íä òåêñò èíãýæ õàðàãäàíà. Õýðâýý òà òýãø ºíöºãò äîòîð òåêñòýý áàãòàõã¿é óðò ãýæ ìýäâýë flag -èéã õýðýãëýæ ÷àäàõ áîëëîî. DT_CALCRECT flag íü òåêñòèéí áàãòààõàä õýðýãëýõ ºíäðèéã áîääîã. Ýíý flag –èéã õýðýãëýæ áàéõàä õàðèí òåêñòýý áè÷èæ ºãºõã¿é . Windows òåêñòèéã áàãòààõàä õýð çýðýã ºíäºðòýé òýãø ºíöºãò áàéõûã õýëæ ºãíº. Òýãýýä Windows áàãòàõ ºíäðººð íü òýãø ºíöºãòèéí ç¿¿íýýñ ýõëýí ººð÷èëæ ã¿éöýòãýäýã áàéíà. Ýíý flag îëîí ìºð òåêñòèéã áè÷èõýä ìàø ÷óõàë à÷ õîëáîãäîëòîé áàéäàã. Äîîðõ æèøýýíä windows -îîñ òåêñòýý áàãòààõ òýãø ºíöºãòèéíõºº ºíäðèéã àñóóæ, òýð ºíäðººð íü òýãø ºíöºãòºº çóðààä äýýð íü òåêñòýý áè÷èæ áàéãàà êîä÷èëîëûã áè÷èâ. procedure TForm1.Button1Click(Sender: TObject); Var R: TRect; S: string; begin R:=Rect(20,150,150,200); Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  19. 19. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ S:='This is very long string which will '+'run into multiple lines of text'; DrawText(Canvas.Handle, Pchar(s),-1,R,DT_CALCRECT or DT_WORDBREAK); Canvas.Brush.Style:=bsSolid; Canvas.Rectangle(R.Left,R.Top,R.Right,R.Bottom); Canvas.Brush.Style:=bsClear; DrawText(Canvas.Handle, Pchar(s),-1,R, DT_WORDBREAK); end; DrawText -èéí 2 äàõ ïàðàìåòð string áèø òåêñò ïàðàìåòð áîëîõîîð ìàññèâûí çààã÷èéã øààðääàã ó÷èðààñ Pchar(s) ãýæ áè÷ñýí áàéíà. Òýìäýãëýë: Õýðýâ òà Delphi 1.0 –èéã àøèãëàæ áàéãàà áîë String –ã Pchar ëóó áîëãîõäîî StrPCopy ôóíêöûã õýðýãëýýðýé. Æèøýý íü: Var Temp: array [0..3]of Char; R : TRect; S : string begin DrawText(Canvas.Handle, StrPCopy(Temp,S), -1, R,DT_CALCRECT or DT_WORDBREAK); Õàðèí Delphi 1.0 –ýýñ äýýøèõ õóâèëáàðóóäàä áîë Pchar –ã ºìíºõ æèøýýòýé àäèë õýðýãëýýðýé . Ýíý êîä÷èëîëîî ôîðìûíõîî OnPaint event äýýð òàâèàä ïðîãðàìàà àæèëëóóëààðàé. ̺í òåêñòèéíõàà óðòûã ººð÷ëººä ¿çýýðýé. Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  20. 20. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ Èíãýõýä ýíý íü ÿìàð ÷ àñóóäàëã¿é òà õè÷íýýí èõèéã íýìæ áè÷ñýí ÷ òýãø ºíöºãò òàíû òåêñòèéí ãàäíààð õ¿ðýýëýãäñýí áàéõ áîëíî. Ǻâëºãºº: Õýðýâ òàíä òåêñò áè÷èõ îëîí cîíãîëò õýðýãòýé áàéãàà áîë DrawTextEx ôóíêöûã õýðýãëýýðýé. Win32API-èéí online help –ñ ìýäýýëëèéã àâààðàé. Òýìäýãëýë: DrawText äýýð òåêñò áè÷èõ íü TextOut -èéã õýðýãëýõýýñ àðàé óäààí áàéäàã. Õýðâýý òàíû çóðãèéí áîëîâñðóóëàëò õóðäàí áàéõ øààðäëàãàòàé áîë TextOutì-èéã õýðýãëýõ íü çîõèìæòîé. Ãýõäýý ýíý 2 íü çàð÷ìûí õóâüä õîîðîíäîî ÿëãààã¿é þì. DrawText íü ìàø ºðãºí õýðýãëýýòýé. Bitmap çóðàõ Bitmap çóðàõ íü íèëýýí õýö¿¿ þì øèã ñàíàãääàã. Õàðèí òà ¿¿íèéã ¿çñýíèéõýý äàðàà ìàø õÿëáàðõàí ç¿éë áàéíà ãýæ áîäîõ áîëíî. Òýãýõýýð TCanvas –ä Btmap çóðàõàä çîðèóëàãäñàí õýäýí method –óóä áàéäàã. Ýäãýýðýýñ õàìãèéí èõ õýðýãëýãääýã method áîë Draw. Ýíý íü Canvas äýýðõ ãàðàõ áàéðëàëûã çààæ ºãºõºä ë õàíãàëòòàé. Îäîî õýäýí æèøýý àâúÿ. procedure TForm1.Button1Click(Sender: TObject); Var Bitmap: TBitmap; Begin Bitmap:= TBitmap.Create; Bitmap.LoadFromFile('c:co.bmp'); Canvas.Draw(0,0,Bitmap); Bitmap.Free; end; Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  21. 21. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ Ýíý æèøýýíä ºãºãäñºí çóðãèéí ôàéëààñ TBitmap îáüåêò ¿¿ñãýæ ôîðìûí ç¿¿í äýýä áóëàíä ãàðãàæ ¿ç¿¿ëæ áàéíà. Bitmap –äàà ÿìàð ÷ ººð÷ëºëò îðóóëàõã¿éãýýð ãàðãàæ ¿ç¿¿ëáýë Draw -èéã õýðýãëýýðýé. Õýðâýý õýìæýýã íü ººð÷èëæ ãàðãàìààð áàéãàà áîë StretchDraw method -èéã õýðýãëýýðýé. Èíãýõäýý Bitmap -èéíõàà ãàðàõ òýãø ºíöºãòèéí õýìæýýã çààæ ºãíº. Õýðâýý Bitmap -èéí ººðèéíõ íü õýìæýýíýýñ òîìîîð çààâàë çóðàã ÷èíü stretched áîëæ ãàðíà. Õàðèí æèíõýíý õýìæýýíýýñ íü áàãààð çààæ ºãâºë áàãàñãàæ ãàðãàõ áîëíî. Æèøýý íü: procedure TForm1.Button1Click(Sender: TObject); Var Bitmap: TBitmap; R: TRect; Begin Bitmap:= TBitmap.Create; Bitmap.LoadFromFile('c:co.bmp'); R:=Rect(0,0,100,100); Canvas.StretchDraw(R,Bitmap); Bitmap.Free; end; Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  22. 22. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ Òýìäýãëýë: StretchDraw –ààð bitmap -èéí æèíõýíý õàðàãäàõ õàðüöààã ººð÷ëºõ ãýæ îðîëäñîíû ÷ õýðýãã¿é. ßàãààä ãýâýë Bitmap -èéíõàà æèíõýíý ºíäºð ºðãºíèéõºº õàðüöààã õàäãàëæ õàìãààëñàí áàéäàã. Ìºí ººð íýã CopyRect method áàéäàã. Ýíý method ¿íäñýí ãàðàõ òýãø ºíöºãòèéíõºº áèå áà õóâààãäàõ òýãø ºíöºãòèéíõºº î÷èõ áèåèéã çààæ ºãºõºä áîëíî. Íýã ¸ñîíäîî bitmap -àà õýñýãò õóâààæ ¿ç¿¿ëýõ áîëîìæ ºã÷ áàéãàà þì. Æíü: Var Bitmap: TBitmap; Src: TRect; Dst: TRect; I, X, Y :Integer; Strips: Integer; Stripsize: Integer; OldPal: Hpalette; Begin Bitmap:= TBitmap.Create; Bitmap.LoadFromFile(‘factory.bmp’); Strips :=6; Stripsize:=(Bitmap.Height div Strips); OlsPal:= SelectPalette(Canvas.Handle,Bitmap.Palette,True); Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  23. 23. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ For I:=0 to Pred(Strips) do begin Src:=Rect(0,I*Stripsize)……. Ýíä çóðãàà îðóóëæ èðýýä çóðààñíóóäàä ç¿ñ÷ ñàíàìñàðã¿éãýýð áàéðëàëûã ¿ç¿¿ëæ áàéíà. Ýíý êîäûã ººðºº ¿íäñýí ôîðìûíõîî OnPaint handler îðóóëæ òóðøèæ ¿çýýðýé. Òýãýõýýð èë¿¿ îéëãîìæòîé áîëíî. Çóðàã onPaint event àæèëëàõ áîëãîíä çóðàãäàõ áîëíî. Òýìäýãëýë: ªìíºõ æèøýýíä Palette ôóíêöûã àøèãëàæ áàéõàä ôîðìûí palette -èéã Bitmap Palette property –ä òîãòîîæ ºãñºí. Ó÷èð íü canvas –ò Palette áàéäàãã¿é. Èéìýýñ ôîðìäîî API -ã àøèãëààðàé. Õýðâýý Palette -àà òîãòîîæ ºãººã¿é áîë ôîðìäýýð Bitmap -èéã ãàð÷ áàéõàä ºí㺠áóðóó ãàðíà. CopyRect method bitmap -èéã ãàðãàõàä á¿òýö õýðýãëýãääýã. Èéìýýñ óã ôóíêöèéã õýðãýëæ áàéõàä íýìýëò àëõàì øààðäëàãàòàé. Áàñ íýã ººð bitmap drawing method áàéäàã òóõàé äóðüäàõûã õ¿ñ÷ áàéíà. the BrushCopy method ¿íäñýí òýãø ºíöºãòèéí î÷èõ òýãø ºíöºãò, çóðàã, transparent color -èéã çààæ ºãºõ áîëîìæèéã îëãîäîã. Online help BrushCopy –ä ýíý method -èéã õýðýãëýõýýñýý èë¿¿ ImageList component -èéã õýðýãëýõèéã çºâëºäºã. BrushCopy method íü ImageList –èéã áîäâîë õýðýãëýõýä õÿëáàð, ãî¸ õàðàãäóóëàõ áîëîâ÷ õóãàöàà èë¿¿ çàðöóóëäàã. Õýðâýý transparent background –òàé bitmap -èéã õýðýãëýæ áàéãàà áîë çààâàë BrushCopy -ã õýðýãëýýðýé. Offscreen Bitmap Offscreen bitmaps, ìºí bitmaps memory ãýæ äóóäàæ áîëäîã. Ýíý íü Windows ïðîãðàì÷ëàëä ýíãèéíýýð õýðýãëýãääýã. Offscreen bitmaps òàíä çóðãàà ñàíàõ îéä õàäãàë÷èõààä äàðàà íü Draw method –îîð ¿ç¿¿ëýõ áîëîìæ îëãîäîã. Offsreen Bitmaps help áîãèíî õóãàöààíä äýëãýöýíä ãàðãàõûí òóëä àøèãëàãääàã. Ýíý íü îëîí óäàà øóóä çóðàõàä ãàðäàã àíèâ÷èõ ¿çýãäëýýñ çàéëñõèéäýã. ̺í complex Bitmap ïðîãðàì÷ëàõàä ìàø ç¿ãýýð áàéäàã. Çóðãàà ñàíàõ îéä õàäãàëààä äýëãýöýíä ¿ç¿¿ëýõàä áýëýí áîëãîæ áýëòãýäýã. OffscreenBitmaps Microfofts DirectX SDK animation –ä õàìãèéí ºðãºí äýëãýðñýí øèíý òåõíîëîãè. Offscreen Bitmap -èéí ïðîöåññ 3 àëõàìààñ á¿ðäýíý. ¯¿íä: Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  24. 24. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ 1. Bitmap memory ¿¿ñãýíý. 2. Bitmap memory äýýð çóðíà. 3. Bitmap memory –ã äýëãýö ðóó õóóëàõ. Memory Bitmap ¿¿ñãýõ Bitmap memory (ñàíàõ îé ) ¿¿ñãýõ íü õÿëáàð áàéäàã. Memory Bitmap –àà ¿¿ñãýæ áàéõàä öàã òóòàìä TBitmap îáúåêò ¿¿ñýæ áàéõ áîëíî. Ýíý ¿åä memory bitmap -ä ôàéëàà õàäãàëíà. Äàðàà íü memory bitmap ¿¿ñãýýä, õýìæýýã çààæ ºã÷ ãàðãàíà. Æèøýý íü: Form äýýð íýã button àâ÷ ò¿¿íèéõýý OnClick event –ä òóðøèæ ¿çýýðýé. Button äàðàõ á¿ðä òýãø ºíöºãò ñàíàìñàðã¿éãýýð çóðàãäàí äýëãýöýíä õàðàãäàõ áîëíî. Bitmap memory õÿëáàðõàí çóðàãäàõ áà canvas –ò Bitmap –àà õóóëäàã. Õýðýâ 256 ºíãºò video adapter õýðýãëýæ áàéãàà áîë ºíãºí¿¿ä dithered áîëíî. Ó÷èð ýíü æèøýýíä Palette õèéãýýã¿é áîëíî. Òýìäýãëýë: Memory Bitmap ¿¿ñãýæ áàéõäàà Bitmap èéí ºí㺠video ¿ç¿¿ëýõ ºíãºíèé òîõèðãîîòîé èæèë áàéõ ¸ñòîé. Õýðâýý video display 256 ºíãºí äýýð ñîíãîñîí áîë Bitmap 256 ºíãºòýé áàéíà. õàðèí 24 - 32 bit video display -òàé áîë memory bitmap 32k, 64k ýñâýë 16 ñàÿ ºíãºòýé áàéõ áîëíî. Memory Bitmap –ã õàäãàëàõ Memory Bitmap –ã õàäãàëàõäàà SaveToFIle ïðîöåäóðûã äóóäíà. BITMAP.SAVETOFILE(‘TEST.BMP’); Òà íàð ïðîãðàìûíõàà äýëãýöèéã àìàðõàí ¿¿ñãýæ ÷àääàã. Ýíý á¿ãäèéã òà ¿íýíäýý memory Bitmap –ä äýëãýöèéíõýý õýñãèéã õóóëæ áàéãàà þì. Multimedia Programming Multimedia programming ãýäýã ¿ã íü îëîí óòãûã èëýðõèéëäýã. Ó÷èð íü multimedia program -ä áîëîìæèéí á¿õ ºðãºí õ¿ðýýã ººðòºº àãóóëñàí áàéäàã. Multimedia íü åðäèéí wave audio, MIDI video clips, animation çýðãèéã Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  25. 25. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ áàãòààäàã. Çàðèì õ¿ì¿¿ñ multimedia ïðîãðàì÷ëàëûã òîãëîîìûí ïðîãðàì÷ëàëòàé àíäóóðäàã. Òîãëîîìûí ïðîãðàì÷ëàë íü multimedia –òàé ãàðöààã¿é õîëáîîòîé áîëäîã. Ãýâ÷ sound, video –òîé èë¿¿ õîëáîîòîé. Îäîî graphics ýñâýë multimedia API -èéí òóõàé òîäîðõîé õýëáýë OpenGL ýñâýë DierctDraw -èéí òóõàé àâ÷ ¿çüå. Graphics ïðîãðàì÷ëàëûí òóõàé èõ ìýäýýëýëòýé íîì õýðýãëýâýë ñàéí ìýðãýæèõ áîëíî. Delphi 4.0 Unleased (ISBN: 0-672-312-859) íîì ñàéí ñîíãîëò áàéõ áîëíî. TMediaPlayer êîìïîíåíò VCL íü õÿëáàðõàíààð Multimedia óäèðäàõ MediaPlayer êîìïîíåíòîîð õàíãàäàã. Ýíý êîìïîíåíò íü Component Palette –èéí System tab -ä áàéðëàäàã. Wave files, AVI video … -ã òîãëóóëæ ÷àäíà. TMediaPlayer –èéã õýðýãëýõýä ìàø àìàðõàí. Ǻâõºí Wave file òîãëóóëàõûí òóëä áè PlaySound ôóíêöûã ºìíºõ æèøýýíä õýðýãëýñýí. Ýíý êîíòðîëä Play, Pause, Stop, Next, Previous, Step, Back, Record, Eject ãýñýí button -óóä áàéäàã. MediaPlayer -èéí ôîðìûã ¿ç¿¿ëëýý. Ýíý MediaPlayer-èéã õýðýãëýõ ìàø ýíãèéí þì. FileName property –ä multimedia ôàéëûí íýðèéã îíîîñíîîð òîâ÷èí äýýð äàðàõàä òîãëóóëæ ýõýëäýã. Èíãýõäýý .wave, .mid, .avi file –óóäûã ñîíãîæ áîëíî. Òà MedioPlayer -àà èë¿¿ ñîíèðõîëòîé õèéìýýð áàéãàà áîë ñàéí óõàæ òºâõºæ ¿çýýðýé. Çàðèì íºõöºëä MediaPlayer -èéí visual control bar èõ ç¿ãýýð õàðàãääàã. Ìàãàäã¿é òà MediaPlayer –àà control bar (Items –ã¿éãýýð) õèéìýýð áàéãàà áîë MediaPlayer –èéí Play, Start, Stop, Rewind êîäûã Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  26. 26. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ íàðèéí àðãààð õèéãýýðýé. Õýðâýý Media Player -èéí runtime ¿åä õàðàãäóóëàõã¿éã õ¿ñâýë Visible –ã False óòãàòàé áîëãîîðîé. Wave Audio áà Windows API Windows API function –íèé òóõàé ýíãèéí ç¿éë¿¿äèéã ÿðèìààðã¿é áàéíà. Wave ôàéëûã òîãëóóëõàä Win32API –èéí PlaySound ôóíêöèéã àøèãëàæ áîëíî. Ýõëýýä òà íàð Mmsystem –ýý ººðèéíõºº õýðýãëýã÷äèéã list áîëãîõîîð íýìíý. Äàðàà íü PlaySound ôóíêöýý äîîðõ áàéäëààð äóóäíà. PlaySound(‘test.wav’,0,SND_FILENAME); Àìàðõàí áàéãàà áèç? PlaySound –í ýõíèé ïàðàìåòðò ÿìàð ôàéë òîãëóóëàõàà çààæ ºãíº. Ñ¿¿ëèéí ïàðàìåòðò äóó õýðõýí òîãëîãäîõ flag -èéã òîãòîîæ ºãíº. Äèñêíýýñ wave audio òîãëóóëæ áàéõäàà ñ¿¿ë÷èéí ïàðàìåòðò òà SND_FILENAME ãýæ òîãòîîæ ºãíº. Òà ººð flag çààæ ºã÷ áîëíî. Õàðèí ýíý òîõèîëäîëä çºâõºí PlaySound ôóíêö íü ìºí äèñêýíäýýð ôàéëòàé èæèë sounds system òîãëóóëæ ÷àäíà. Cèñòåìèéí äóóã òîãëóóëàõäàà ýõíèé ïàðàìåòðò íü sound alies -èéã çààæ ºãíº. Õàðèí flags ïàðàìåòðò SND_ALIES ãýæ æèøýýíäýý çààæ ºã÷ýý. PlaySound (‘SystemAsterisk’,0,SND_ALIES); Ýíý êîä íü ñèñòåìèéí äóó Asterisk –èéã òîãëóóëíà. Ñèñòåìèéí äóóíû æàãñààëòûã îëæ àâõûã òóëä Ñontrol Panel –èéí Sound àpplet –èéã àæèëëóóë. Õýðâýý ñèñòåìèéí äóó îëäîõã¿é áîë windows default äóóã òîãëóóëíà. Default äóó íü ding áàéäàã. Òýìäýãëýë: Win32API MessageBeep ôóíêö ìºí system sound -ã èíäåêñèéí äóãààðààð íü òîãëóóëäàã. Win32 online help –ñ MessageBeep -í òóõàé á¿õ ìýäýýëëèéã õàðààðàé. Play sound ôóíêö äóóäàõ ¿åä 2 ººð ÷óõàë flags áàéíà. • SND_ASYNC flag íü äóóã àñèíõðîí òîãëîõûã çºâøººðäºã. Ýíý flag õýðýãëýãäýæ áàéõàä äóó òîãëîæ ýõëýõäýý øóóä ïðîãðàìûí òîîëóóðûã Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  27. 27. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ ïðîãðàìðóó áóöààäàã. Ýíý íü òàíû ïðîãðàì äàðààãèéí êîìàíäàà àæèëóóëæ áàéõàä sound òîãëîñîîð áàéõ áîëíî ãýñýí ¿ã. • SND_SYNC flag íü äóóã òîãëîæ äóóñàõ õ¿ðòýë ïðîãðàìûí òîîëóóðûã ïðîãðàìðóó áóöààõã¿éãýýð çààæ ºãäºã. SND_SYNC íü PlaySound –í default ó÷èðààñ ýíý flag-ã òîäîðõîéëæ ºãºõ õýðýãã¿é. Ýíä ìàø îëîí flag-óóä PlaySound -ð äóóã ÿàæ òîõèðóóëàõàä õýðýãëýãäýíý. Á¿ðýí ìýäýýëëèéã Win32 online help äýýð PlaySound ôóíêö ãýñýí õýñãýýñ õàðààðàé. MediaPlayer –èéí Properties, Method, áà Event TMediaPlayer –ò ìàø îëîí property áàéäàã. Òýäãýýðèéí èõýíõ íü îéëãîõîä õÿëáàð, õàðèí çàðèì íü áàãà çýðãèéí òºâºãòýé áàéäàã. TmediaPlayer -èéí ¿íäñýí ãîë øèíæ ÷àíàðóóäûã æàãñààæ áè÷èâ. Property Òàéëáàð AutoOpen Ìedia ôàéëûã àâòîìàòààð íýýõ ýñýõ AutoRewind True ¿åä Media ôàéëûã òîãëóóëñíû äàðàà media –ãèéí áàéðëàëûí çààã÷ media -ãèé ýõëýë äýýð î÷èõ ýñýõ. . Default: true DeviceType Multimedia òºõººðºìæèéí õýëáýð. DtAutoSelect áàéâàë DeviceType filename -í ºðãºòãºë äýýð aâòîìàòààð ñîíãîãäîíî. Default: dtAutoSelect Display Video ôàéëûí òîãëîõ ìóæ. Default íü øèíýýð öîíõ ¿¿ñãýæ òîãëóóëíà. DisplayRect Video -íû ¿ç¿¿ëýõ òýãø ºíöºãòèéí õýìæýýã òîõèðóóëíà. EnableButtons MediaPlayer –èéí òîâ÷íóóäûã òóñ á¿ðýýð íü èäâýõòýé ýñýõèéã òîäîðõîéëíî. Default:Allbuttons EndPos Media –íû ñ¿¿ëèéí áàéðëàë. Mediaplayer íü ôàéëûã startPos -îîñ EndPos õ¿ðòýë òîãëîíî. Õýðýâ EndPos ãýæ òîäîðõîéëîîã¿é áîë media ôàéëûí òºãñºë õ¿ðòýë íü òîãëîäîã. Óòãà íü EndPos ãýæ òîãòîîãäñîí áîë Media play –í òîãëîæ áàéãààãààñ õàìààðíà. Error Õàìãèéí ñ¿¿ëèéí àëäààíû êîä. Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  28. 28. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ ErrorMessage Õàìãèéí ñ¿¿ëèéí àëäààíû òåêñò òàéëáàð. Frames Óðàãøàà ýñâýë õîéøîî ã¿éëãýõ ¿åä õýäýí frame –ýýð øèëæèõèéã òîäîðõîéëíî. Length Media -ãèéí òîãëóóëæ áàéãàà òºðºë, TimeFormat -í óòãà á¿ðýýñ õàìààðñàí media –ãèéí óðò. Mode Device –èéí òºëºâ. MpNotReady, mpStopped, mpPlaying ãýõ ìýò áàéíà. Notify True ¿åä MediaPlayer -èéí ÿìàð íýã ¿éëäýë äóóñàõàä OnNotify event ¿¿ñíý. NotifyValue Ñ¿¿ëèéí ìýäýãäëèéí ¿ð ä¿í. Position Media -ãèéí îäîîãèéí áàéðëàë. StartPos Media -ãèéí ýõëýõ áàéðëàë. Media íü Startpos -c EndPos õ¿ðòýë òîãëîíî. Startpos ãýæ òîäîðõîéëîîã¿é áîë media íü ýõíýýñ íü òîãëîäîã. StartPos íü media òîãëîæ áàéãàà õýëáýðýýñ õàìààð÷ òîãòîîíî. TimeFormat Òîãëóóëàõ òºõººðºìæèä timeformat õýðýãëýãäýíý. Timeformat íü milliseconds, frames, bytes, samples, tracks /minutes/seconds,hours/minutes/seconds…áàéíà. Tracks Media àãóóëàõ ìºðèéí òîî (Cdaudio devices) VisibleButtons MediaPlayer –èéí êîíòðîëèéí òîâ÷íóóäûã òîõèðóóëíà. Wait Óäèðäëàãûã ïðîãðàìðóó øóóä áóöààäàã ýñâýë çºâõºí media òîãëîæ äóóññàíû äàðàà áóöààäàã ýñýõ. TMediaPlayer –ò ìºí îëîí method áàéäàã. Property Òàéëáàð Back Frames property -îîð òîãòîîãäñîí àëõàìààð media -ã óõðààõ Close Òîãëóóëàõ òºõººðºìæèéã õààõ Ejeñt Eject õèéõ Next Òºõººðºìæèéí äàðààãèéí ìºðèéí ýõëýë Open Òîãëóóëàõ òºõººðºìæèéã íýýõ Pause Òîãëîõ ïðîöåñûã ò¿ð çîãñîîõ Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  29. 29. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ Previous ªìíºõ ôàéëûã òîãëóóëàõ Resume Òîãëóóëàõ áîëîí ðåêîðäûí ¿éë àæèëëàãààã ñýðãýýõ Rewind Media äàõèí áàéðíààñàà ýõëýõ Save FileName property –ð òîãòîîãäñîí ôàéëûã õàäãàëàõ Startrecord Statrrecord(ºãºãäëèéí) Step Frames property -îîð òîãòîîãäñîí óðàãøëóóëàõ òîî. Stop Îäîîãèéí ¿éëäëèéã çîãñîîõ TMediaPlayer êîìïîíåíòîä çºâõºí íýã event áàéäàã. OnNotify event íü êîìàíä ã¿éöýòãýæ äóóñõàä äóóäàãääàã. Õàðèí çºâõºí Notify property -ãèéí óòãà true ¿åä òà àëäààã øàëãàæ áîëíî. NotifyValue Property íü óòãûã õàðàõ ¿éëäëèéã àìæèëòòàé ýñýõèéã çààíà. Wave Audio Multimedia -ãèéí îëîí ¿íäñýí ¿éëäë¿¿äèéí íýã íü Wave audio òîãëóóëàõ þì. ýíý íü ìàãàäã¿é åðäèéí ¿éëäýë þì. Wave file synchronously òîãëóóëæ áàéõàä: Play.wait:=true; Player.filename:=’testwav.wav; Player.open; Player.play; Ýíä wave property true wave ôàéëûí òîãëîõ òºëºâ íü synchronously áàéíà. Player.FileName := ‘test.wav’; Player.Open; Player.StartPos := 1000; Player.EndPos := 3000; Player.Play; Òýìäýãëýë: Õýðýâ StartPos, EndPos –èéí óòãóóä áóðóó áàéâàë wave ôàéëûã òîãëóóëæ ÷àäàõã¿é. Áóðóó ºãºãäºë ãýäýãò startPos, EndPos –ýýññ èõ ýñâýë EndPos –èéí óòãà Media ôàéëûí óðòààñ èõ çýðýã áàãòàíà. Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  30. 30. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ Äóóíû õýìæýýã òîõèðóóëàõ Wave òºõººðºìæèéí äóóã òîõèðóóëàõ íü õàðüöàíãóé àìàðõàí ç¿éë þì. Windows API ¿¿íèéã õèéíý. WaveOutgetvolume áà WaveOutsetvolume ôóíêö¿¿ä äóóíû öàð õ¿ðýýã òîõèðóóëæ ÷àäíà. Volume íü integer óòãà àâíà. ªíäðèéã íü áàðóóí, ñóëûã íü ç¿¿í òàëûí volume òîõèðóóëãààð õèéíý. Òýã óòãà íü äóóã¿é áà $FFFF (hex) áàéâàë õàìãèéí ÷àíãà ãýõ ìýò÷èëýí ºãíº. waveOutSetVolume(0, $FFFFFFFF); WaveOutsetVolume ôóíêö íü çºâõºí wave á¿òýýãäýõ¿¿íèé äóóã òîõèðóóëíà. Master äóóã çºâõºí multimedia mixer control -îîð òîõèðóóëäàã. Wave Audio áè÷ëýã õèéõ Óã ñýäýâ íü òèéì àìàð ç¿éë áèø. ßàãààä ãýâýë wave ôàéë áè÷èõäýý ýõëýýä áè÷èãäýõ wave ôàéëàà íýýíý. Ýíý íü áè÷èõòýéãýý èæèë ïàðàìåòðòýé øèíý ôàéë áàéíà. Òýãýýä äàðàà øèíý ºãºã뺺 áè÷íý. Filename property -èéí name -èéã ººð÷ëºõ áà ò¿¿íäýý õàäãàëíà. Ýíý á¿ãä áàãà çýðýã òºâºãòýé. Æèøýý íü: Filename DUMMY.wav ýíý ôàéë 22050kHz –èéí WaveFormat -òàé áîëíî. Òîâ÷èí äýýð äàðàõ ¿åä òà wave audio -îîð áè÷èæ ýõýëíý. Ýíý ¿åä áè÷èõ ¿éë ÿâö ýõýë÷èõñýí áà óäèðäëàãà òàíû application ðóó áóöààíà. Îäîî çîãñîîõ õýðýãòýé . Äîîð æèøýýíä ¿ç¿¿ëýâ. procedure TForm1.StartBtnClick(Sender: TObject); begin with MediaPlayer do begin FileName := ‘dummy.wav’; Open; Wait := False; StartRecording; end; end; procedure TForm1.StopBtnClick(Sender: TObject); begin with MediaPlayer do begin Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  31. 31. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ { Áè÷èõ ïðîöåñèéã çîãñîîæ áàéíà } Stop; { ôàéëûí íýðèéã ººð÷èëºí, õàäãàëíà} FileName :=’new.wav’; { Õàäãàëàõ áà õààíà } Save; Close; end; end; Òýìäýãëýë: Áè÷èæ áàéõ ¿åä ýíý àëõàìûã wave audio recording ã¿éöýòãýõ øààðäëàãàòàé. MediePlayer -èéí áàéðëàëûã îëîõûí òóëä Record method äóóä. Áè÷ëýã õèéõ ¿ç¿¿ëýëò¿¿ä íü äàðààõ áàéäàëòàé áàéíà. ¯¿íä: õóðä, õîîëîéíû òîî (mono, stereo) bits –í òîî, (èõýâ÷ëýí 8 ýñâýë 16) çýðýã õýâ ìàÿãóóä áàéäàã. Åðäèéí wave form -èéí òîãëóóëàõ äàâòàìæ íü 8000kHz, 11025KHz, 22050kHz, 44150kHz áàéäàã. Õàìãèéí ºíäºð äàâòàìæòàé audio áè÷ëýã äýýä çýðãèéí ÷àíàðòàé. Ìàãàäã¿é òà òîãëîîì õèéãýýã¿é áîë stereorecord -èéã õýðýãëýõã¿é áàéõ. ̺í bits -èéí òîî íü äóó áè÷ëýãèéí ÷àíàðò íºëººëäºã. Ýíý íü èõýâ÷ëýí 8 ýñâýë 16 áàéäàã. Òýìäýãëýë: ªíäºð ÷àíàðòàé äóóã áè÷èõ äèñêíû èõýíõ çàéã èõýýð ýçýëäýã. Wave file -àà stereo -îîð áè÷èæ áàéõàä íýã õîîëîéãîîð áè÷ñýí ôàéëààñ õýìæýý íü 2 äàõèí èõ áîëäîã. 16 bits –ã õýðýãëýõ íü wave ôàéëàà 8 bits äýýð òàâüæ 2 äàõèí áè÷ñýíòýé àäèë þì. Ôàéëàà 22050kHz õóðäòàé, òîîí áà 8 bits per -òàé áè÷ñýí áîë ýíý íü 200K. ¯¿íèé àäèëààð 22050kHz stereo 16 bits per-ð áè÷ñýí áîë 800K áîëíî. Èõýíõäýý stereo, 16 bits per -ýýð áè÷èõ íü äèñêíû çàéã èõýýð ýçýëäýã. 22050kHz, òîî íü 8 bits per -ýýð áè÷èõ íü ç¿ãýýð áàéäàã áà äóóíû ÷àäàë ôàéëûí õýìæýýíä òîõèðäîã. MIDI Audio MIDI audio –ãèéí òàëààð èõèéã íóðøèõ õýðýãã¿é áàéõ. ¯¿íèéã òà MediePlayer -èéí FileName property –ä MIDI ôàéë ãýæ ñîíãîîä Play method –èéã äóóäàõàä áîëíî. Èõýíõ sound card íýã çýðýã 2 wave file –èéã òîãëóóëàõ áîëîìæ ºãäºãã¿é. ¯¿íòýé àäèë íýãýí çýðýã íýãýýñ îëîí file-èéã MIDI file –ä òîãëóóëàõ áîëîìæã¿é áàéäàã. Õýäèéã èéì áîëîâ÷ MIDI file áîëîí wave file 2 -èéã çýðýã òîãëóóëàõ áîëîìæèéã îëãîäîã. Ýíý íü òîãëîîì òîãëîæ áàéõàä Music Track áà Sound effect íýãýí çýðýã òîãëóóëæ áàéäãèéã õýëæ áàéãàà Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  32. 32. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ þì. Òà èíãýæ Wave, MiDI ôàéëóóäûã çýðýã òîãëóóëìààð áàéâàë MediaPlayer -èéí êîìïîíåíòòýé àæèëëàíà. Òîãëóóëàõäàà MediaPlayer –àà MIDI ôàéëä, PlaySound –àà wave ôàéëä õýðýãëýýðýé. MIDI file èõýâ÷ëýí òîãëîîìûí background äóóíä õýðýãëýãääýã. Õýðâýý MIDI file -àà èéì áàéäëààð õýðýãëýæ áàéãàà áîë äóó òºãñãºë人 õ¿ðýõ ¿åä äàõèí ýõë¿¿ëæ áàéãààðàé. TMediaPlayer –íü èéì äóóã ¿ðãýëæèëñíýýð íü òîãëóóëæ ÷àääàãã¿é. Èéì áîëîâ÷ òà MideaPlayer-í OnNotify event –èéã äàâòàõ ýôôåêò áîëãîæ õýðýãëýýðýé. ¯¿íèé äàðàà OnNotify event handler –ààð õàíãàõ õýðýãòýé. Ýíý event handler –ò àìæèëòòàé òîãëîæ äóóññàíû äàðàà MIDI äàõèí ýõë¿¿ëýõ êîä÷èëîë õýðýãòýé. Æèøýý íü: procedure TForm1.MediaPlayerNotify(Sender: TObject); begin with MediaPlayer do if NotifyValue = nvSuccessful then begin Position := 0; Play; end; end; Ýíý æèøýý íü NotifyValue property -ã nvSuccessfull óòãàòàé ýñýõèéã øàëãàæ áàéíà. Position 0 áàéíà. Ýíý íü ôàéë äàõèí òîãëîæ ýõýëñíýýð play method äóóäàãäàíà ãýñýí ¿ã. Ýíý á¿ãä ìàø ýíãèéí áàéíà. Õýäýí ÿðâèãòòàé àñóóäëóóä áèé. Òýäãýýðèéí òàëààð ìýäýæ àâàõ ¸ñòîé. Ýõíèéõ íü Position property 0 ãýæ ºãñºí. Ýíý íü ôàéëûã äàõèí ýõëýëä íü ýðã¿¿ëýõ íºëººòºé. Õýâýý autoRewind property true óòãàòàé áàéâàë ýíý íü áîëîìæã¿é. Õî¸ð äàõ íü ýíä íèëýýä õýäýí MediaPlayer ¿éë àæèëëàãàà áàéíà. ò¿¿íèéã ìýäýæ àâàõ . Ýíä OnNotify event NotifyValue íü successful óòãàòàéãààð äóóäàãäàæ áàéãàà ¿éëäýë þì. Æèøýýëáýë óòãà íü nvSuccesfull óòãàòàé áàéâàë êîìàíä äóóñàõààñ õàìààðàí Stop êîìàíäûí ¿¿ðýã ãàðíà. CD Audio Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  33. 33. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ CD òîãëóóëàõ íü õàðüöàíãóé àìàðõàí. CD òîãëóóëàõäàà Device Type property –ã dtCDAudio -ààð òîãòîîæ ìºí Play button äàðàãäàõàä ýñâýë Play method äóóäààðàé. CD Audio òîãëóóëàõûí òóëä CDAudio –ä Different TimeFormat õýðýãëýãääýãèéã îéëãîõ õýðýãòýé. Òà TMSF –èéã õýðýãëýæ áàéãàà áîë (öàã, ìèíóò, ñåêóíä, ôðàéì) TimeFormat òîäîðõîé ìºð ýñâýë current áàéðëàëààñ òîäîðõîé ìºð ë¿¿ ãýñýí ìýäýýëýëòýé áîëíî. ßìàð íýã ìèíóò , ñåêóíä ýñâýë ôðàéìûí óòãûã ìºðèéí äóãààð áîëãîæ òàâüÿ. Æèøýýíä current track äîòðîõ playing position-ã string –ð çààæ ºã÷ áàéíà.: var Time : Integer; Track : Integer; Minutes : Integer; Seconds : Integer; TimeStr : string; begin MediaPlayer.TimeFormat := tfTMSF; Time := MediaPlayer.Position; Track := mci_TMSF_Track(Time); Minutes := mci_TMSF_Minute(Time); Seconds := mci_TMSF_Second(Time); TimeStr := Format(‘Track Time: %2.2d:%2.2d’, [Minutes, Seconds]); Label1.Caption := ‘Track: ‘ + IntToStr(Track); Label2.Caption := TimeStr; end; Ýõëýýä TimeFormat –èéã TMSF ãýæ ºã÷ áàéíà. Äàðàà íü Time äóóäàãäàæ current position -íèé õýìæèãäõ¿¿í õàäãàëàãäàæ áàéíà. Track, Minute, Second ãýñýí ººð óòãóóä windows Time-èéí (mci_TMSF_Track…) ãýñýí ººð÷ëºëòéèã àâ÷ áàéíà. MM system unit –ä macro -yóäûã àãóóëàãääàã. Õýðýâ ýäãýýð ìàêðîíóóäûã õýðýãëýâýë ýíý õýñãýý òà ººðèéíõºº uses List -ä íýìýýðýé. ªºðñäèéíõºº öàãèéí óòãóóäûã àâ÷ äóóññàíû äàðàà Time string ìºðèéí öàãèéã ¿ç¿¿ëýõýýð ¿¿ñãýíý. Òýãýýä ìºðèéí äóãààð áà ìºðèéí öàã Label component -ä ãàð÷ èðíý. MSF (minute,second,frames) –èéã ãýñýí TimeFormat õýðýãëýæ áàéãàà CD global level àâàõ áîëíî. Æèøýý íü MSF TimeFormat – èéã current podition –ã CD –íèé ýõëýë ãýñýí õóó÷èí õýâä îðóóëàõàä õýðýãëýýðýé. ¯¿íòýé èæèë MSF TimeFormat -èéã CD -íèé current position -ã CD äýýðõ 30 ìèíóòûí õýìæýýòýé ìºðä ãýæ çààæ ºã÷ áîëíî. Äîîðõ æèøýý Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  34. 34. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ íü ìºðíèé òóõàéä áèø ÿàæ áóöààæ õóó÷èí õýâä íü îðóóëàí ¿ç¿¿ëæ áàéãààã õàðóóëàâ. CD äýýðõ ìèíóò áà ñåêóíäèéã current position : var Time : Integer; Minutes : Integer; Seconds : Integer; TimeStr : string; begin MediaPlayer.TimeFormat := tfMSF; Time := MediaPlayer.Position; Minutes := mci_MSF_Minute(Time); Seconds := mci_MSF_Second(Time); TimeStr := Format(‘Total Time: %2.2d:%2.2d’, [Minutes, Seconds]); Label3.Caption := TimeStr; end; Ýíý æèøýý íü ÑDPlayer òîãëóóëàõ ïðîãðàìûã àãóóëñàí áàéíà. ̺í TMediaPlayer Audio CDPlayer -èéã ¿¿ñãýõýä õýðõýí õýðýãëýãäýæ áàéãààã áàãòààñàí áàéíà. AVI Video TmediaPlayer -ýýð AVI video òîãëóóëàõûí òóëä AVI ôàéëàà ñîíãîîä Play method –îî äóóäíà. (ýñâýë Play button äàðíà.) Õýðýâ default MediaPlayer – èéí òîõèðãîî õýðýãëýæ áàéãàà áîë òóñäàà öîíõ íü pop up áîëæ AVI ¿¿íäýýð ãàðàõ áîëíî. ̺í Display Property -ã ÿìàð íýã öîíõ òºðëèéí êîìïîíåíòèéã çààæ ºãñíººð video òýð êîìïîíåíòèéí ìóæèä òîãëîõ áîëíî. Æèøýý íü: Panel äýýð AVI video -ãîî òîãëóóëáàë äàðààõ õýëáýðòýé áè÷íý. MediaPlayer.Display := AVIPanel; Panel äýýð AVI video òîãëóóëæ áàéõàä ä¿ðñ õàðàãäàõ áîëíî. Õýðýâ video íü Panel -èéí òýãø ºíöºãòººñ òîì òýð video Panel –ä õàé÷ëàãäàæ õýìæýýã íü á¿ðýí ãàðãàõã¿é áîëãîíî. ¯¿íèéã Strech ýñâýë Shrink áîëãîæ video -ãîî õàðâàë DisplayRect property -ã Stretch ýñâýë Shrink ãýæ çààæ ºãººðºé. MEDIAPLAYER.DISPLAYRECT := AVIPANEL.CLIENTRECT; Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò
  35. 35. ªºðºº ººðòºº çààõ íü: Borland Delphi 4 http://www.csms.edu.mn/cheri/ ¯¿íä AVI video –íû îëîí òºðëèéí format áàéíà. Ãýâ÷ á¿õ AVI –ã system ä¿¿ðýí òîãëîõã¿é. Õýðâýý áàòàëãààòàé òîãëóóëàõûã õ¿ñâýë standard Microfoft AVI video type -èéã îðóóëààðàé. ßàãààä òàíû õýðýãëýã÷ ãàðöààã¿é Microsoft AVI ñóóëãàñàí áàéíà. Óã íîìíû áóñàä á¿ëãèéã http://www.csms.edu.mn/cheri/ õàÿãààñ àâààðàé. ☺ Áîëîâñðóóëñàí: îþóòàí Á. Íàðàíöàöðàë SW02D090 Õÿíàñàí: áàãø ×. Ýðäýíýáàò

×