我的位图是一个箭头,需要根据不同的角度指向不同的方向,该如何实现呢?
请教!
请教!
解决方案 »
- 关于导入头文件
- 如果是高手,请帮我解决一个消息传递的问题。
- 请问如何使用位操作将10进制数转换为2进制?
- 如何调用存储过程。大家帮帮小弟啊~~。
- 如何得到系统安装的所有软件的安装路径?如何判断系统中是否安装了某个软件?
- 怎么得到CreateFont里的默认字体宽度?(实在没分了,请原谅)
- DLL调用
- 写这样的语句:_RecordsetPtr m_pRecordset;需要增加什么样的头文件?类型_RecordsetPtr编译器不认,怎么解决这个问题?
- 动态调用动态连接库出错--马上结帖(急急急)
- 请问,滚动视图的滚动条的出现可以编程中控制吗?
- 高分求救关于PacketSendPacket死机的问题(在线等待)
- 在TreeCtrl控件中,加入了checkbox的风格。那当我在checkbox 中打勾时会引发什么消息呀?
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]);
}
}
}
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);
}
用不同的位图替换
agree
http://www.codeproject.com/vcpp/gdiplus/
不知你指的是指速度问题还是其他方面?
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);
改为double试一试