Sub btnConvert_Click
Dim In As InputStream
Dim c1,cr As Canvas
Dim r As Rect
Dim bmp1, bmpr As Bitmap
ImageView2.SetBackgroundImage(Null)
c1.Initialize(ImageView1)
cr.Initialize(ImageView2)
In = File.OpenInput(File.DirAssets, ImageName)
Jpg1.LoadJpegSizeOnly(In)
In = File.OpenInput(File.DirAssets, ImageName)
bmp1 = Jpg1.LoadJpegSmaller(In, Jpg1.JpegHeight/ImageView1.Height)
' Jpg2 = Jpg1
bmpr.InitializeMutable(Jpg1.JpegWidth,Jpg1.JpegHeight)
Jpg1.SetPixelsFromBmp(bmp1)
Jpg1.PixelsABGRtoARGB
Jpgr.SetPixelsFromBmp(bmpr)
' Jpgr.PixelsABGRtoARGB
Dim pixelval As Double
Dim alpha, rd, gn, bl As Byte
'Calculate Offset In order To rotate on image middle
Dim xOffset As Int
Dim yOffset As Int
xOffset = (Jpg1.JpegWidth) / 2
yOffset = (Jpg1.JpegHeight) / 2
' Log("jpg width" & Jpg1.JpegWidth)
' Log("jpg height" & Jpg1.JpegHeight)
Dim degreesRed,degRed As Float
degreesRed = SeekBar1.Value
Dim degreesGreen,degGreen As Float
degreesGreen = SeekBar2.Value
Dim degreesBlue,degBlue As Float
degreesBlue = SeekBar3.Value
Dim img_rd(Jpg1.BmpWidth,Jpg1.BmpHeight) As Byte
Dim img_gn(Jpg1.BmpWidth,Jpg1.BmpHeight) As Byte
Dim img_bl(Jpg1.BmpWidth,Jpg1.BmpHeight) As Byte
For x = 0 To Jpg1.BmpWidth-1
For y = 0 To Jpg1.BmpHeight-1
img_rd(x,y) = 0
img_gn(x,y) = 0
img_bl(x,y) = 0
Next
Next
Dim rx_bl, ry_bl, rx_rd, ry_rd, rx_gn, ry_gn As Float
'Convert To Radians
degBlue = (degreesBlue) * 3.14159 / 180
degGreen = (degreesGreen) * 3.14159 / 180
degRed = (degreesRed) * 3.14159 / 180
For x = 0 To Jpg1.BmpWidth - 1
For y = 0 To Jpg1.BmpHeight - 1
pixelval = Jpg1.GetBmpPixel(x, y)
If CheckBox1.Checked = False Then
rd=0
rx_rd = x
ry_rd = y
Else
rd = Bit.UnsignedShiftRight(Bit.AND(pixelval, 0xff0000), 16)
rx_rd = Floor((x - xOffset) * Cos(degRed)) - ((y - yOffset) * Sin(degRed)) + xOffset
ry_rd = Floor((x - xOffset) * Sin(degRed)) + ((y - yOffset) * Cos(degRed)) + yOffset
End If
If CheckBox2.Checked = False Then
gn=0
rx_gn = x
ry_gn = y
Else
gn = Bit.UnsignedShiftRight(Bit.AND(pixelval, 0xff00), 8)
rx_gn = Floor((x - xOffset) * Cos(degGreen)) - ((y - yOffset) * Sin(degGreen)) + xOffset
ry_gn = Floor((x - xOffset) * Sin(degGreen)) + ((y - yOffset) * Cos(degGreen)) + yOffset
End If
If CheckBox3.Checked = False Then
bl=0
rx_bl = x
ry_bl = y
Else
bl = Bit.AND(pixelval, 0xff)
rx_bl = Floor((x - xOffset) * Cos(degBlue) - (y - yOffset) * Sin(degBlue)) + xOffset
ry_bl = Floor((x - xOffset) * Sin(degBlue) + (y - yOffset) * Cos(degBlue)) + yOffset
End If
Try 'some x or y values might be negative or larger than bipmap height and/or width - so, try and catch
img_rd(Floor(rx_rd),Floor(ry_rd)) = rd 'store new red coordinates
Catch
End Try
Try
img_gn(Floor(rx_gn),Floor(ry_gn)) = gn 'store new green coordinates
Catch
End Try
Try
img_bl(Floor(rx_bl),Floor(ry_bl)) = bl 'store new blue coordinates
Catch
End Try
Next
Next
For x = 0 To Jpg1.BmpWidth - 1
For y = 0 To Jpg1.BmpHeight - 1
Jpgr.SetBmpPixel(x, y, Colors.ARGB(255,Bit.AND(img_rd(x,y),255), Bit.AND(img_gn(x,y),255), Bit.AND(img_bl(x,y),255) ))
Next
Next
bmpr = Jpgr.GetBmpFromPixels
In.Close
r.Initialize(0, 0, ImageView1.Width, ImageView1.Height)
c1.DrawBitmap(bmp1, Null, r)
ImageView1.Invalidate
r.Initialize(0, 0, ImageView2.Width, ImageView2.Height)
cr.DrawBitmap(bmpr, Null, r)
ImageView2.Invalidate
End Sub