我的位图是一个箭头,需要根据不同的角度指向不同的方向,该如何实现呢?
请教!

解决方案 »

  1.   

    旋转位图函数#include <math.h> /* 
    radians, 弧度,3.14相当于180度 
    clrBack, 背景色
    XX, 中心点X坐标 
    YY, 中心点Y坐标 
    Height, Height of bitmap 
    Width, width of bitmap 
    Source, pointer to a CBitmap 
    Center CPoint, of the center off set, 0,0 is the center - is top left + botom right 
    theHDC, the HDC 
    */ void RotatedBitmap2(float radians, 
    COLORREF clrBack, 
    int XX, 
    int YY, 
    int Height, 
    int Width, 
    CBitmap *Source, 
    CPoint Center, 
    HDC theHDC); void RotatedBitmap2(float radians, COLORREF clrBack, int XX, int YY, int Height, int Width, CBitmap *Source, CPoint Center, HDC theHDC) 

    CDC Bitmap_DC; 
    Bitmap_DC.CreateCompatibleDC( NULL ); 
    Bitmap_DC.SelectObject(Source); 
    COLORREF C[4]; 
    double Pi = 3.14159265359; 
    int c1x; 
    int c1y; 
    float a=0; 
    int r; 
    int p1x; 
    int p1y; 
    int p2x; 
    int p2y; 
    int n; 
    float cosine = (float)cos(radians); 
    float sine = (float)sin(radians); 
    int modX = (int)(Center.x*cosine + Center.y*sine); 
    int modY = (int)(Center.y*cosine - Center.x*sine); c1x = Width / 2; 
    c1y = Height / 2; 
    n = sqrt((c1x * c1x) + (c1y * c1y)); 
    for(p2x = 0;p2x<n;p2x++) 

    for(p2y=0;p2y<n;p2y++) 

    if(p2x==0)a=Pi/2.0; 
    else a=tanh(p2y/(p2x*1.0)); 
    r = sqrt(p2x*p2x + p2y*p2y); 
    p1x = (int)(p2x*cosine - p2y*sine); 
    p1y = (int)(p2y*cosine + p2x*sine); 
    C[0] = Bitmap_DC.GetPixel(c1x + p1x,c1y + p1y); 
    C[1] = Bitmap_DC.GetPixel(c1x - p1x,c1y - p1y); 
    C[2] = Bitmap_DC.GetPixel(c1x + p1y,c1y - p1x); 
    C[3] = Bitmap_DC.GetPixel(c1x - p1y,c1y + p1x); 
    if(C[0] !=clrBack&&C[0] !=-1) ::SetPixel(theHDC,c1x + p2x+XX+modX, c1y + p2y+YY+modY, C[0]); 
    if(C[1] !=clrBack&&C[1] !=-1) ::SetPixel(theHDC,c1x - p2x+XX+modX, c1y - p2y+YY+modY, C[1]); 
    if(C[2] !=clrBack&&C[2] !=-1) ::SetPixel(theHDC,c1x + p2y+XX+modX, c1y - p2x+YY+modY, C[2]); 
    if(C[3] !=clrBack&&C[3] !=-1) ::SetPixel(theHDC,c1x - p2y+XX+modX, c1y + p2x+YY+modY, C[3]); 


      

  2.   

    下面是一段画箭头程序,或许有用。
    void DrawArrow(CDC *pdc,CPoint m_One, CPoint m_Two)
    {
    double slopy , cosy , siny;
    double Par = 10.0;//length of Arrow (>)
    slopy = atan2( ( m_One.y - m_Two.y ),
    ( m_One.x - m_Two.x ) );
    cosy = cos( slopy );
    siny = sin( slopy ); //draw a line between the 2 endpoint
    pdc->MoveTo( m_One );
    pdc->LineTo( m_Two );

    //here is the tough part - actually drawing the arrows
    //a total of 6 lines drawn to make the arrow shape
    pdc->MoveTo( m_One);
    pdc->LineTo( m_One.x + int( - Par * cosy - ( Par / 2.0 * siny ) ),
    m_One.y + int( - Par * siny + ( Par / 2.0 * cosy ) ) );
    pdc->LineTo( m_One.x + int( - Par * cosy + ( Par / 2.0 * siny ) ),
    m_One.y - int( Par / 2.0 * cosy + Par * siny ) );
    pdc->LineTo( m_One );
    /*/-------------similarly the the other end-------------/*/
    pdc->MoveTo( m_Two );
    pdc->LineTo( m_Two.x + int( Par * cosy - ( Par / 2.0 * siny ) ),
    m_Two.y + int( Par * siny + ( Par / 2.0 * cosy ) ) );
    pdc->LineTo( m_Two.x + int( Par * cosy + Par / 2.0 * siny ),
    m_Two.y - int( Par / 2.0 * cosy - Par * siny ) );
    pdc->LineTo( m_Two );
    }void CArrowView::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    m_Drag = true;// for mouse drag check
    PointOrigin = point;// value when mouse drag starts
    CView::OnLButtonDown(nFlags, point);
    }void CArrowView::OnLButtonUp(UINT nFlags, CPoint point) 
    {
    m_Drag = false;// for mouse drag check
    MotionFix=0;
    CView::OnLButtonUp(nFlags, point);
    }void CArrowView::OnMouseMove(UINT nFlags, CPoint point) 
    {
    // only draw arrow if drag mode and different points
    if (m_Drag && PointOrigin!=point )
    {
    CClientDC ClientDC (this);
    ClientDC.SetROP2(R2_NOT); if (MotionFix) DrawArrow(&ClientDC,PointOrigin,PointOld);
    MotionFix++;
    DrawArrow(&ClientDC,PointOrigin,point);

    }
    PointOld = point;
    CView::OnMouseMove(nFlags, point);
    }
      

  3.   

    可以将图片的像素取出来,再用一定的编移显示出来,就可以了。
    用不同的位图替换
    agree
      

  4.   

    to Powerdix(大山)效果不是很好啊,可能是我还不太会用,给个示例好吗?
      

  5.   

    图形的旋转、缩放,最简单的方法是用GDI+,参考一下
    http://www.codeproject.com/vcpp/gdiplus/
      

  6.   

    把::SetPixel()改成::SetPixelV()试一试。
    不知你指的是指速度问题还是其他方面?
      

  7.   

    XFORM xForm; 
    SetGraphicsMode(hDC, GM_ADVANCED);
    xForm.eM11 = (FLOAT) cos(degree); 
    xForm.eM12 = (FLOAT) sin(degree); 
    xForm.eM21 = (FLOAT) -sin(degree); 
    xForm.eM22 = (FLOAT) cos(degree); 
    xForm.eDx  = (FLOAT) 0.0; 
    xForm.eDy  = (FLOAT) 0.0; 
    SetWorldTransform(hDC, &xForm); BitBlt(hdc,x,y,cx,cy,hMemDC,0,0,SRCCOPY);
      

  8.   

    是锯齿或者float的精度太低?
    改为double试一试
      

  9.   

    never do that in your source code,the speed of your application will be madly affected,it is a really a bad performance to your users.if you insist on doing so ,you will have to restrict the rotation of angle to an int,and never use the tri-angle function to set the value,you need to create your own index table to search the value.then see your own powerful masterpiece.