<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Qyoto 中的繪圖 > 原文: [http://zetcode.com/gui/csharpqyoto/painting/](http://zetcode.com/gui/csharpqyoto/painting/) 在 Qyoto C# 編程教程的這一部分中,我們將進行繪圖。 當我們在京都進行繪圖時,`QPainter`類非常有用。 繪圖事件通過`OnPaintEvent()`方法接收。 若要進行自定義繪圖,我們必須重新實現此方法。 ## 圖案 在《京都議定書》中,我們可以使用各種圖案來填充形狀的內部。 ```cs using System; using QtCore; using QtGui; /** * ZetCode Qyoto C# tutorial * * This program draws nine rectangles. * The interiors are filled with * different built-in patterns. * * @author Jan Bodnar * website zetcode.com * last modified November 2012 */ public class QyotoApp : QMainWindow { public QyotoApp() { WindowTitle = "Patterns"; PaintEvent += OnPaintEvent; Resize(350, 280); Move(300, 300); Show(); } private void OnPaintEvent(object sender, QEventArgs<QPaintEvent> e) { QPainter ptr = new QPainter(this); DrawPatterns(ptr); ptr.End(); } void DrawPatterns(QPainter ptr) { ptr.SetPen(Qt.PenStyle.NoPen); ptr.SetBrush(Qt.BrushStyle.HorPattern); ptr.DrawRect(10, 15, 90, 60); ptr.SetBrush(Qt.BrushStyle.VerPattern); ptr.DrawRect(130, 15, 90, 60); ptr.SetBrush(Qt.BrushStyle.CrossPattern); ptr.DrawRect(250, 15, 90, 60); ptr.SetBrush(Qt.BrushStyle.Dense7Pattern); ptr.DrawRect(10, 105, 90, 60); ptr.SetBrush(Qt.BrushStyle.Dense6Pattern); ptr.DrawRect(130, 105, 90, 60); ptr.SetBrush(Qt.BrushStyle.Dense5Pattern); ptr.DrawRect(250, 105, 90, 60); ptr.SetBrush(Qt.BrushStyle.BDiagPattern); ptr.DrawRect(10, 195, 90, 60); ptr.SetBrush(Qt.BrushStyle.FDiagPattern); ptr.DrawRect(130, 195, 90, 60); ptr.SetBrush(Qt.BrushStyle.DiagCrossPattern); ptr.DrawRect(250, 195, 90, 60); } [STAThread] public static int Main(String[] args) { new QApplication(args); new QyotoApp(); return QApplication.Exec(); } } ``` 在代碼示例中,我們將繪制九個矩形,并用不同的畫筆圖案填充它們。 ```cs PaintEvent += OnPaintEvent; ``` 在繪制事件中執行繪制。 我們將`OnPaintEvent()`方法插入到繪畫事件。 ```cs private void OnPaintEvent(object sender, QEventArgs<QPaintEvent> e) { QPainter ptr = new QPainter(this); DrawPatterns(ptr); ptr.End(); } ``` 當需要重繪窗口區域時,將調用`OnPaintEvent()`方法。 當我們調整窗口大小,最大化或最小化窗口時,就會發生這種情況。在此方法中,我們創建了`QPainter`對象。 該對象用于完成 Qyoto 中的所有繪圖。 繪圖本身被委托給`DrawPatterns()`方法。 `End()`方法釋放繪圖時使用的資源。 ```cs ptr.SetPen(Qt.PenStyle.NoPen); ``` 筆對象用于繪制形狀的輪廓。 在我們的示例中,我們將不使用筆。 ```cs ptr.SetBrush(Qt.BrushStyle.HorPattern); ``` 我們將水平圖案設置為畫筆。 ```cs ptr.DrawRect(10, 15, 90, 60); ``` 我們使用當前的筆和畫筆繪制一個矩形。 該方法的前兩個參數是 x,y 坐標。 最后兩個參數是矩形的寬度和高度。 ![Patterns](https://img.kancloud.cn/9a/a0/9aa03f30abece400abcdc7bede5e85f2_356x305.jpg) 圖:圖案 ## 形狀 Qyoto 繪圖 API 可以繪制各種形狀。 以下編程代碼示例將顯示其中的一些。 ```cs using System; using System.Collections.Generic; using QtGui; using QtCore; /** * ZetCode Qyoto C# tutorial * * This program draws basic shapes * available in Qyoto. * * @author Jan Bodnar * website zetcode.com * last modified November 2012 */ public class QyotoApp : QMainWindow { public QyotoApp() { WindowTitle = "Shapes"; PaintEvent += OnPaintEvent; Resize(350, 280); Move(300, 300); Show(); } private void OnPaintEvent(object sender, QEventArgs<QPaintEvent> e) { QPainter ptr = new QPainter(this); DrawShapes(ptr); ptr.End(); } void DrawShapes(QPainter ptr) { ptr.SetRenderHint(QPainter.RenderHint.Antialiasing); ptr.Pen = new QPen(new QBrush(new QColor("Gray")), 1); ptr.Brush = new QColor("Gray"); QPainterPath path1 = new QPainterPath(); path1.MoveTo(5, 5); path1.CubicTo(40, 5, 50, 50, 99, 99); path1.CubicTo(5, 99, 50, 50, 5, 5); ptr.DrawPath(path1); ptr.DrawPie(130, 20, 90, 60, 30*16, 120*16); ptr.DrawChord(240, 30, 90, 60, 0, 16*180); ptr.DrawRoundRect(20, 120, 80, 50); List<QPoint> points = new List<QPoint>(); points.Add(new QPoint(130, 140)); points.Add(new QPoint(180, 170)); points.Add(new QPoint(180, 140)); points.Add(new QPoint(220, 110)); points.Add(new QPoint(140, 100)); QPolygon polygon = new QPolygon(points); ptr.DrawPolygon(polygon); ptr.DrawRect(250, 110, 60, 60); QPointF baseline = new QPointF(20, 250); QFont font = new QFont("Georgia", 55); QPainterPath path2 = new QPainterPath(); path2.AddText(baseline, font, "Q"); ptr.DrawPath(path2); ptr.DrawEllipse(140, 200, 60, 60); ptr.DrawEllipse(240, 200, 90, 60); } [STAThread] public static int Main(String[] args) { new QApplication(args); new QyotoApp(); return QApplication.Exec(); } } ``` 在此代碼示例中,我們在窗口上繪制了九種不同的形狀。 復雜路徑,餅圖,和弦,圓角矩形,多邊形,矩形,基于字符的形狀,圓形和橢圓形。 ```cs ptr.SetRenderHint(QPainter.RenderHint.Antialiasing); ``` 我們在示例中使用抗鋸齒。 抗鋸齒形狀看起來更好,但是繪制它們需要更多時間。 ```cs ptr.Pen = new QPen(new QBrush(new QColor("Gray")), 1); ptr.Brush = new QColor("Gray"); ``` 我們使用深灰色的筆和畫筆繪制形狀。 ```cs QPainterPath path1 = new QPainterPath(); path1.MoveTo(5, 5); path1.CubicTo(40, 5, 50, 50, 99, 99); path1.CubicTo(5, 99, 50, 50, 5, 5); ptr.DrawPath(path1); ``` 使用`QPainterPath`對象創建第一個復雜形狀。 `QPainterPath`類為繪圖操作提供了一個容器。 畫家路徑是由許多圖形構造塊(例如矩形,橢圓形,直線和曲線)組成的對象。 ```cs ptr.DrawPie(130, 20, 90, 60, 30*16, 120*16); ptr.DrawChord(240, 30, 90, 60, 0, 16*180); ptr.DrawRoundRect(20, 120, 80, 50); ``` 這三行畫出一個餅圖,一個和弦和一個圓角矩形。 ```cs List<QPoint> points = new List<QPoint>(); points.Add(new QPoint(130, 140)); points.Add(new QPoint(180, 170)); points.Add(new QPoint(180, 140)); points.Add(new QPoint(220, 110)); points.Add(new QPoint(140, 100)); QPolygon polygon = new QPolygon(points); ptr.DrawPolygon(polygon); ``` 我們使用五個點的列表來創建多邊形。 ```cs QPointF baseline = new QPointF(20, 250); QFont font = new QFont("Georgia", 55); QPainterPath path2 = new QPainterPath(); path2.AddText(baseline, font, "Q"); ptr.DrawPath(path2); ``` 這些線創建基于字符的形狀。 ```cs ptr.DrawEllipse(140, 200, 60, 60); ptr.DrawEllipse(240, 200, 90, 60); ``` 這兩條線分別創建一個圓和一個橢圓。 ![Shapes](https://img.kancloud.cn/47/8e/478eee4c52e3235b6b017ebb5a02264b_356x305.jpg) 圖:形狀 ## 透明矩形 透明性是指能夠透視材料的質量。 了解透明度的最簡單方法是想象一塊玻璃或水。 從技術上講,光線可以穿過玻璃,這樣我們就可以看到玻璃后面的物體。 在計算機圖形學中,我們可以使用 alpha 合成來實現透明效果。 Alpha 合成是將圖像與背景組合以創建部分透明外觀的過程。 合成過程使用 Alpha 通道。 (wikipedia.org,answers.com) ```cs using System; using QtCore; using QtGui; /** * ZetCode Qyoto C# tutorial * * This program draws ten rectangles with * different levels of transparency. * * @author Jan Bodnar * website zetcode.com * last modified November 2012 */ public class QyotoApp : QMainWindow { public QyotoApp() { WindowTitle = "Transparent rectangles"; PaintEvent += OnPaintEvent; Resize(590, 90); Move(300, 300); Show(); } private void OnPaintEvent(object sender, QEventArgs<QPaintEvent> e) { QPainter ptr = new QPainter(this); DrawRectangles(ptr); ptr.End(); } void DrawRectangles(QPainter ptr) { ptr.SetPen(Qt.PenStyle.NoPen); for (int i=1; i<11; i++) { ptr.Brush = new QColor(0, 0, 255, i*25); ptr.DrawRect(50*i, 20, 40, 40); } } [STAThread] public static int Main(String[] args) { new QApplication(args); new QyotoApp(); return QApplication.Exec(); } } ``` 在示例中,我們將繪制十個具有不同透明度級別的矩形。 ```cs ptr.SetPen(Qt.PenStyle.NoPen); ``` 我們不用筆。 ```cs for (int i=1; i<11; i++) { ptr.Brush = new QColor(0, 0, 255, i*25); ptr.DrawRect(50*i, 20, 40, 40); } ``` `QColor`對象的最后一個參數是 alpha 透明度值。 ![Transparent rectangles](https://img.kancloud.cn/06/28/062818c5414b78ef1b9b1b6cda348f85_596x115.jpg) 圖:透明矩形 ## 繪制文字 在最后一個示例中,我們將在窗口上繪制文本。 ```cs using System; using QtCore; using QtGui; /** * ZetCode Qyoto C# tutorial * * This program draws text * on the window. * * @author Jan Bodnar * website zetcode.com * last modified November 2012 */ public class QyotoApp : QMainWindow { public QyotoApp() { WindowTitle = "Soulmate"; PaintEvent += OnPaintEvent; Resize(370, 240); Move(300, 300); Show(); } private void OnPaintEvent(object sender, QEventArgs<QPaintEvent> e) { QPainter ptr = new QPainter(this); DrawLyrics(ptr); ptr.End(); } void DrawLyrics(QPainter ptr) { ptr.Brush = new QColor(25, 25, 25); ptr.Font = new QFont("Courier", 10); ptr.DrawText(new QPoint(20, 30), "Most relationships seem so transitory"); ptr.DrawText(new QPoint(20, 60), "They're good but not the permanent one"); ptr.DrawText(new QPoint(20, 120), "Who doesn't long for someone to hold"); ptr.DrawText(new QPoint(20, 150), "Who knows how to love without being told"); ptr.DrawText(new QPoint(20, 180), "Somebody tell me why I'm on my own"); ptr.DrawText(new QPoint(20, 210), "If there's a soulmate for everyone"); } [STAThread] public static int Main(String[] args) { new QApplication(args); new QyotoApp(); return QApplication.Exec(); } } ``` 我們在窗口上畫一首歌歌詞。 ```cs ptr.Font = new QFont("Courier", 10); ``` 我們為文本設置了 Courier 字體。 ```cs ptr.DrawText(new QPoint(20, 30), "Most relationships seem so transitory"); ``` `DrawText()`方法用于在`x = 20`,`y = 30`處繪制文本。 ![Drawing text](https://img.kancloud.cn/96/ec/96ecb93a9113f49f034f80eaf8e1670f_378x267.jpg) 圖:繪制文本 在 Qyoto C# 編程教程的這一部分中,我們做了一些繪圖。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看