1 / 9

Klasa grafik

Klasa grafik.

felix
Download Presentation

Klasa grafik

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Klasagrafik

  2. Sistemskekontrolemozemokoristitiizacrtanjeraznihoblika, sto se postizeikoriscenjemmetodaugradjenklase Graphics. Objekatklase Graphics predstavljapovrsinupokojoj se crta.Prvogamoramokreirati,sto se postizepozivanjemmetodeCreateGraphics() zanekukontrolu ,kreira se objekatklase Graphics tako da je povrsinazacrtanjeupravo ta kontrola. • KlasaGraphics sadrzimetodezacrtanjeraznihoblika, izmedjuostalihi : • Drav Line – zacrtanjelinije • DrawEllipse- zacrtanjeelipse • DrawRectangle- zacrtanjepravougaonika • DrawArc –zacrtanjeproizvoljnogluka • DrawBezier-zacrtanjekrivelinijeokocetritacke • FillELLIPSE – ZA CRTANJE POPUNJENE ELIPSE • FillRectangle –zacrtanjepoopunjenogpravougaonika • Prostorzacrtanjebrisemometodom Clear klaseGraphics • Npr. g.Clear(Color.White); objekatklaseGraphics se popunjavabelombojom

  3. KreiraniobjekatklaseGraphics zauzimaodgovarajuceresursenaseg Sistema pa je potrebno , pozavrsetkucrtanja , oslobodititeresursekoriscenjemmetode Dispose() klaseGraphics . Prikoriscenjumetodazacrtanjeneophodno je kreiratioluvku (objekatklase Pen) akozelimo da crtamokonturezeljenogoblikailicetku (objekatklaseSolidBrush) akozelimopopunjenioblik. Klasa Pen je definisana u imenskomprostoruSystemDrawing. Objektomklase Pen definisemosirinu, bojuistillinije.Stil je definisansvojstvomDashStylecija je vrednosttipaDashStyledefinisanog u imenskomprostoruSystem.Drawing.Drawing2D. Objekatklase Pen kreiramopozivomkonstruktora.najcesce se pozivakonstruktorkomepredajemo, kao parameter redombojuisirinuobjekta. Nprobjekatolovkaklase Pencija je bojacrvena a sirina 5, kreiramonasledecinacinPen olovka=new Pen(Color.red,5);Kadzavrsimosakoriscenjemobjektaklase Pen potrebno je osloboditiresursekojetajobjekatkoristioolovka.Dispose();

  4. 1. Kreiratiaplikacijukojom se u PictureBoxucrtajudijagonale, pravougaonikilielipsa. Izborrealizovatikorišćenjem tri kontrole Button. private void btDijagonale_Click(object sender, EventArgs e) { pictureBox1.Refresh(); Graphics g=pictureBox1.CreateGraphics(); Pen olovka=new Pen(Color.Red,3); g.DrawLine(olovka,0,0,pictureBox1.Width,pictureBox1.Height); g.DrawLine(olovka,pictureBox1.Width,0,0,pictureBox1.Height); olovka.Dispose(); // nijeneophodno g.Dispose(); // nijeneophodno } private void btPravougaonik_Click(object sender, EventArgs e) { // kreiranjegrafickogobjekta Graphics g=pictureBox1.CreateGraphics(); // ciscenjeprostorazacrtanje g.Clear(Color.White); // kreiranjeolovkecrveneboje, sirine 3 Pen olovka=new Pen(Color.Red,3); // crtanjepravougaonika g.DrawRectangle(olovka,10,10, pictureBox1.Width-20 , pictureBox1.Height-20); olovka.Dispose(); g.Dispose(); }

  5. private void btElipsa_Click(object sender, EventArgs e) { pictureBox1.Refresh(); Graphics g=pictureBox1.CreateGraphics(); Pen olovka=new Pen(Color.Red,3); g.DrawEllipse(olovka,10,10, pictureBox1.Width-20 , pictureBox1.Height-20); olovka.Dispose(); g.Dispose(); } 3. Kreirati aplikaciju kojom se a) zadato r crtaslikakaonacrtežu, krugovisusacentom u srediniobjektakalsePixtureBox, prvikrug je datogpoluprečnika r, a svakisledeći je za 10 veći od prethodnog

  6. private void btCrtez1_Click(object sender, EventArgs e) { Graphics g = pictureBox1.CreateGraphics(); Pen olovka = new Pen(Color.Blue, 2); int w = pictureBox1.Width; int h = pictureBox1.Height; g.Clear(Color.White); g.DrawLine(olovka, w / 2, 0, 0, h / 2); g.DrawLine(olovka, 0, h / 2, w / 2, h); g.DrawLine(olovka, w / 2, h, w, h / 2); g.DrawLine(olovka, w, h / 2, w / 2, 0); olovka.Width = 5; olovka.Color = Color.Red; int r = Convert.ToInt32(textBox1.Text); g.DrawEllipse(olovka, w / 2 - r, h / 2 - r, 2 * r, 2 * r); r = r + 10; g.DrawEllipse(olovka, w / 2 - r, h / 2 - r, 2 * r, 2 * r); r = r + 10; g.DrawEllipse(olovka, w / 2 - r, h / 2 - r, 2 * r, 2 * r); }

  7. b) crtacržekkaonaslici (objekatklasePictureBox se deli na 9 jednakihdelova)

  8. private void btCrtez2_Click(object sender, EventArgs e) { Graphics g = pictureBox1.CreateGraphics(); Pen olovka = new Pen(Color.Blue, 5); int w = pictureBox1.Width; int h = pictureBox1.Height; g.Clear(Color.White); g.DrawLine(olovka, w / 3, 0, w / 3, h); g.DrawLine(olovka, 2 * w / 3, 0, 2 * w / 3, h); g.DrawLine(olovka, 0, h / 3, w, h / 3); g.DrawLine(olovka, 0, 2 * h / 3, w, 2 * h / 3); olovka.Color = Color.Red; olovka.Width = 3; g.DrawLine(olovka, 0, 0, w / 3, h / 3); g.DrawLine(olovka, w / 3, 0, 0, h / 3); g.DrawLine(olovka, 2 * w / 3, 2 * h / 3, w, h); g.DrawLine(olovka, w, 2 * h / 3, 2 * w / 3, h); SolidBrushcetka = new SolidBrush(Color.Green); g.FillEllipse(cetka, w / 3 + 5, h / 3 + 5, (w / 3 - 10), (h / 3 - 10)); cetka.Color = Color.Yellow; g.FillEllipse(cetka, w / 3 + 20, h / 3 + 20, (w / 3 - 40), (h / 3 - 40)); }

More Related