Option Explicit
Const pi = 3.14159265358979
Private Sub cmdRotate_Click()
Dim nX As Integer, nY As Integer
Dim nX1 As Integer, nY1 As Integer
Dim dX2 As Double, dY2 As Double
Dim dX3 As Double, dY3 As Double
Dim dThetaDeg As Double
Dim dThetaRad As Double
'Initialize rotation angle
dThetaDeg = 45
'Compute angle in radians
dThetaRad = dThetaDeg * pi / 180
'Set scale modes to pixels
picOne.ScaleMode = vbPixels
picTwo.ScaleMode = vbPixels
For nX = 0 To picTwo.ScaleWidth
nX1 = nX - picTwo.ScaleWidth \ 2
For nY = 0 To picTwo.ScaleHeight
nY1 = nY - picTwo.ScaleHeight \ 2
'Rotate picture by dThetaRad
dX2 = nX1 * Cos(-dThetaRad) + nY1 * Sin(-dThetaRad)
dY2 = nY1 * Cos(-dThetaRad) - nX1 * Sin(-dThetaRad)
'Translate to center of picture box
dX3 = dX2 + picOne.ScaleWidth \ 2
dY3 = dY2 + picOne.ScaleHeight \ 2
'If data point is in picOne, set its color in picTwo
If dX3 > 0 And dX3 < picOne.ScaleWidth - 1 _
And dY3 > 0 And dY3 < picOne.ScaleHeight - 1 Then
picTwo.PSet (nX, nY), picOne.Point(dX3, dY3)
End If
Next nY
Next nX
End Sub
void CCONV rotateLng(BITMAP *DC,BITMAP *PW,__int16 dcx,__int16 dcy,__int16 pwx, __int16 pwy,__int16 width, __int16 height,int* lngcolor, BYTE alpha, int pwcx, int pwcy, __int16 angel) //_RotateTrans24AlphaBlt
{
BYTE* cage = (BYTE*)DC->bmBits;
BYTE* what = (BYTE*)PW->bmBits;
bool ident;
int dcbyte, pwbyte;
int rotx,roty;
int curx,cury;
int pxsize = 3;
double y1,x1;
double cosa, sina;
double ang;
BYTE* color = (BYTE*)lngcolor;
if (dcx + width>DC->bmWidth)
width = DC->bmWidth - dcx;
if (dcy + height>DC->bmHeight)
height = DC->bmHeight - dcy;
if (pwx + width>PW->bmWidth)
width = PW->bmWidth - pwx;
if (pwy + height>PW->bmHeight)
height = PW->bmHeight - pwy;
ang = -angel / RADPERDEG;
cosa = cos(ang);
sina = sin(ang);
for (double cy=0;cy<height; cy+=0.5)
{
y1= cy - pwcy;
for (double cx=0;cx<width; cx+=0.5)
{
x1 = cx - pwcx;
rotx = int(x1 * cosa + y1 * sina);
roty = int(y1 * cosa - x1 * sina);
curx = rotx + dcx;
cury = roty + dcy;
if (curx <= DC->bmWidth && cury <= DC->bmHeight && curx>=0 && cury>=0)
{
dcbyte = DC->bmWidthBytes * (dcy + cury) + pxsize * (dcx + curx);
pwbyte = int(PW->bmWidthBytes * int(pwy + cy) + pxsize * int(pwx + cx));
ident=true;
for (int a=0; a<pxsize; a++)
{
if (color[pxsize - a - 1]!=what[pwbyte + a])
{
ident= false;
break;
}
}
if (!ident)
{
for (int cbyte=0;cbyte<pxsize; cbyte++)
{
cage[dcbyte + cbyte] = cage[dcbyte + cbyte] * (255 - alpha) / 255 + BYTE(what[pwbyte + cbyte] * (alpha) / 255);
}
}
}
}
}
return;
}
Сейчас этот форум просматривают: AhrefsBot и гости: 4