Hi StrongM,
I have been trying my luck with the IPicture, and still i found very minimum.. i think am getting stuck in some points, I cant even imagine of a Picture Object in memory and manipulating and copying it to another.. its like trying to figure out the road map of a country where I have never been!
Pls Help...
'This is the function i use (thanks!) to create the DC
Public Function vbGetCompatibleDC() As Long
' Create a screen-compatible memory DC
vbGetCompatibleDC = CreateCompatibleDC(GetDC(0)) ' screen compatible
End Function
Public Function BitRotate(ByRef Source As IPicture, ByVal Angle As Double, ByVal AntiAlias As Boolean) As IPicture
'Store a few attributes of the pictures for increased speed
Dim tmpPic As IPicture
Set tmpPic = Source
' tmpPic.Width = Source.Width
' tmpPic.Height = Source.Height
SourceWidth = Source.Width / Screen.TwipsPerPixelX
SourceHeight = Source.Height / Screen.TwipsPerPixelY
DestWidth = tmpPic.Width / Screen.TwipsPerPixelX
DestHeight = tmpPic.Height / Screen.TwipsPerPixelY
Source.SelectPicture vbGetCompatibleDC(), 0&, 0&
'Allocate array for source picture's bits
ReDim SourceBuffer.Bits(3, SourceWidth - 1, SourceHeight - 1)
With SourceBuffer.Header
.biSize = 40
.biWidth = SourceWidth
.biHeight = -SourceHeight
.biPlanes = 1
.biBitCount = 32
.biSizeImage = 3 * SourceWidth * SourceHeight
End With
'Get source pictures bits
GetDIBits Source.CurDC, Source.Handle, 0, SourceHeight, SourceBuffer.Bits(0, 0, 0), SourceBuffer, 0&
'Allocate array for dest picture's bits
ReDim DestBuffer.Bits(3, DestWidth - 1, DestHeight - 1)
With DestBuffer.Header
.biSize = 40
.biWidth = DestWidth
.biHeight = -DestHeight
.biPlanes = 1
.biBitCount = 32
.biSizeImage = 3 * DestWidth * DestHeight
End With
'Get center of source picture
cx = SourceWidth * 0.5
cy = SourceHeight * 0.5
'Get center of destination picture
dx = DestWidth * 0.5
dy = DestHeight * 0.5
'Convert angle to Sin/Cos radians
cosa = Cos(Angle * Deg2Rad * -1)
sina = Sin(Angle * Deg2Rad * -1)
'Get bounds of source picture
biW = SourceWidth - 1
biH = SourceHeight - 1
SetRect biRct, 0, 0, biW, biH
'Clear dectination picture
'Dest.Cls
For y = 0 To DestHeight - 1
'Destination Y to calculate
yin = y - dy
For x = 0 To DestWidth - 1
'Destination X to calculate
xin = x - dx
'Rotate destination X, Y according to angle in radians
rx = xin * cosa - yin * sina + cx
ry = xin * sina + yin * cosa + cy
'Round of rotated pixels X, Y coordinates
irx = Int(rx)
iry = Int(ry)
'If rotated pixel is within bounds of destination
If (PtInRect(biRct, irx, iry)) Then
'Convert pixel to destination
drx = rx - irx
dry = ry - iry
'If Anti-Alias switch is on
If AntiAlias Then
'Get rotated pixel
r1 = SourceBuffer.Bits(2, irx, iry)
g1 = SourceBuffer.Bits(1, irx, iry)
b1 = SourceBuffer.Bits(0, irx, iry)
'Get rotated pixels right neighbor
r2 = SourceBuffer.Bits(2, irx + 1, iry)
g2 = SourceBuffer.Bits(1, irx + 1, iry)
b2 = SourceBuffer.Bits(0, irx + 1, iry)
'Get rotated pixels lower neighbor
r3 = SourceBuffer.Bits(2, irx, iry + 1)
g3 = SourceBuffer.Bits(1, irx, iry + 1)
b3 = SourceBuffer.Bits(0, irx, iry + 1)
'Get rotated pixels lower right neighbor
r4 = SourceBuffer.Bits(2, irx + 1, iry + 1)
g4 = SourceBuffer.Bits(1, irx + 1, iry + 1)
b4 = SourceBuffer.Bits(0, irx + 1, iry + 1)
'Interpolate pixels along Y axis
ib1 = b1 * (1 - dry) + b3 * dry
ig1 = g1 * (1 - dry) + g3 * dry
ir1 = r1 * (1 - dry) + r3 * dry
ib2 = b2 * (1 - dry) + b4 * dry
ig2 = g2 * (1 - dry) + g4 * dry
ir2 = r2 * (1 - dry) + r4 * dry
'Interpolate pixels along X axis
B = ib1 * (1 - drx) + ib2 * drx
G = ig1 * (1 - drx) + ig2 * drx
R = ir1 * (1 - drx) + ir2 * drx
'Check for valid color range
If (R < 0) Then R = 0 Else If (R > 255) Then R = 255
If (G < 0) Then G = 0 Else If (G > 255) Then G = 255
If (B < 0) Then B = 0 Else If (B > 255) Then B = 255
'Plot interpolated pixel to destination picture
DestBuffer.Bits(2, x, y) = R
DestBuffer.Bits(1, x, y) = G
DestBuffer.Bits(0, x, y) = B
Else
'Get rotated pixel
R = SourceBuffer.Bits(2, irx, iry)
G = SourceBuffer.Bits(1, irx, iry)
B = SourceBuffer.Bits(0, irx, iry)
'Plot rotated pixel to destination picture
DestBuffer.Bits(2, x, y) = R
DestBuffer.Bits(1, x, y) = G
DestBuffer.Bits(0, x, y) = B
End If
End If
Next x
Next y
'Load destination bits to destination picture
SetDIBits tmpPic.CurDC, tmpPic.Handle, 0, DestHeight, DestBuffer.Bits(0, 0, 0), DestBuffer, 0&
Set BitRotate = tmpPic
End Function
Looking eagerly for your reply...
Thanks,
Sunil