zoukankan      html  css  js  c++  java
  • 点绘,线绘,图绘

    绘正方形
    代码部分

    CRect rect;
    GetClientRect(&rect);
    pDC ->SetMapMode(MM_ANISOTROPIC);
    pDC ->SetWindowExt(rect.Width(),rect.Height());
    pDC ->SetViewportExt(rect.Width(),-rect.Height());
    pDC ->SetViewportOrg(rect.Width()/2,rect.Height()/2);


    // CPen NewPen, *pOldPen;
    // NewPen.CreatePen(PS_SOLID, 1, RGB(0, 0, 255));
    // pOldPen = pDC ->SelectObject(&NewPen);
    // pDC ->Rectangle(rect);


    srand((unsigned)time(NULL));
    COLORREF crColor;
    int x, y;
    for (y = 50; y < 150; y++)
    for(x = -150; x < -50; x++)
    pDC ->SetPixelV(x, y, RGB(rand()%255, rand()%255, rand()%255));


    //left to right;first draw inside "for"
    for(x = -150; x < -50; x++)
    for (y = 50; y < 150; y++)
    {
    crColor = pDC ->GetPixel(x, y);
    pDC ->SetPixelV(x + 200, y, crColor);
    }


    //down to up
    // for(y = -50; y < 50; y++)
    // for(x = -150; x < -50; x++)
    // {
    // crColor = pDC ->GetPixel(x,y);
    // pDC ->SetPixelV(x + 200, y - 200, crColor);
    // }


    //up to down
    for(y = 150; y > 50; y--)
    for (x =-150; x < -50; x++)
    {
    crColor = pDC ->GetPixel(x,y);
    pDC ->SetPixelV(x + 200, y - 200, crColor);
    }


    //right to left
    for(x = -50; x > -150; x--)
    for (y = 50; y < 150; y++)
    {
    crColor = pDC ->GetPixel(x, y);
    pDC ->SetPixelV(x, y - 200,crColor);
    }


    //line1
    CPoint p0(-50, 50),p1(50, -50);
    CPen NewPen, *pOldPen;
    NewPen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
    pOldPen = pDC ->SelectObject(&NewPen);
    pDC ->MoveTo(p0);
    pDC ->LineTo(p1);
    /// pDC ->SelectObject(pOldPen);


    //line2
    CPoint p2(-50, -50),p3(50, 50);
    // CPen NewPen, *pOldPen;
    // NewPen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
    // pOldPen = pDC ->SelectObject(&NewPen);
    pDC ->MoveTo(p2);
    pDC ->LineTo(p3);
    pDC ->SelectObject(pOldPen);  
    不看后面的两条线,单看前面部分(为简洁截取一部分为例)  

    for (y = 50; y < 150; y++)
    for(x = -150; x < -50; x++)
    pDC ->SetPixelV(x, y, RGB(rand()%255, rand()%255, rand()%255));
    SetPixelV()很有意思,在指定范围绘线,其实是打点,点成线,最后线成面;应该说它的动态绘图,让人眼睛一亮
    Pen,Brush,lineto(),setPolyFillMode(),FillPath(),strokeAndFillPath()这些就相对要在动态上差很多,完全看不到图形生成的过程,程序一运行,相应图形立刻完全显示出来,没有乐趣享受。如果说SetPixelV()是“点绘图形”的函数的话,那么lineto()就是“线绘图形”的函数,而Brush就有点“图绘图形”的味道。

     线绘图形 
    eg:

    CPen Pen;
    for (x = 0; x <10; x++)
    {
    pDC->SelectObject(&Pen);
    pDC->MoveTo(x, 0);
    pDC->LineTo(x, 9);

    绘制的是一个边为10的正方形,一瞬间间图形就完全显示出来了

    图绘图形

    适用于重复同一个图案的实例,可以是多把刷子轮流使用。

  • 相关阅读:
    App架构师实践指南四之性能优化一
    App架构师实践指南三之基础组件
    App架构师实践指南二之App开发工具
    App架构师实践指南一之App基础语法
    Linux下阅读MHT文件
    What Is Docker & Docker Container ? A Deep Dive Into Docker !
    Difference between Docker Image and Container?
    RabbitMQ .NET/C# Client API Guide
    How RabbitMQ Works and RabbitMQ Core Concepts
    Message Queue vs Message Bus — what are the differences?
  • 原文地址:https://www.cnblogs.com/qbin/p/4979425.html
Copyright © 2011-2022 走看看