Hi Anand, forget it, he also mentioned that he used Photoshop!!
Toby already posted a wonderful project that can do this perfectly.
Sub Globals
Dim imgView As ImageView ' ImageView to display the photo
Dim btnSketch As Button ' Button to trigger the sketch effect
Dim lightFactor As Int = 150 ' Factor to make the sketch lighter
End Sub
Sub Activity_Create(FirstTime As Boolean)
' Initialize UI components
imgView.Initialize("")
btnSketch.Initialize("btnSketch")
' Add UI components to the activity
Activity.AddView(imgView, 10dip, 10dip, 300dip, 300dip)
Activity.AddView(btnSketch, 10dip, 320dip, 100dip, 50dip)
btnSketch.Text = "Sketch"
' Load a sample image (replace with your own image path)
Dim bmp As Bitmap
bmp.Initialize(File.DirAssets, "girl.png")
imgView.Bitmap = bmp
End Sub
Sub btnSketch_Click
Dim originalBmp As Bitmap = imgView.Bitmap
Dim sketchBmp As Bitmap = ConvertToSketch(originalBmp)
imgView.Bitmap = sketchBmp
End Sub
Sub ConvertToSketch(originalBmp As Bitmap) As Bitmap
Dim bc As BitmapCreator
bc.Initialize(originalBmp.Width, originalBmp.Height)
' Load the original bitmap into BitmapCreator
bc.CopyPixelsFromBitmap(originalBmp)
Dim width As Int = bc.mWidth
Dim height As Int = bc.mHeight
' Convert the entire image to grayscale
Dim grayBC As BitmapCreator
grayBC.Initialize(width, height)
Dim argb As ARGBColor
Dim grayMatrix(width, height) As Int
For x = 0 To width - 1
For y = 0 To height - 1
bc.GetARGB(x, y, argb)
' Convert to grayscale
Dim gray As Int = (argb.r + argb.g + argb.b) / 3
grayMatrix(x, y) = gray
' Apply grayscale value to grayBC
argb.r = gray
argb.g = gray
argb.b = gray
grayBC.SetARGB(x, y, argb)
Next
Next
' Edge detection (Sobel filter)
Dim edgeBC As BitmapCreator
edgeBC.Initialize(width, height)
For x = 1 To width - 2
For y = 1 To height - 2
' Sobel X and Y gradients
Dim gX As Int = (grayMatrix(x + 1, y - 1) + 2 * grayMatrix(x + 1, y) + grayMatrix(x + 1, y + 1)) - _
(grayMatrix(x - 1, y - 1) + 2 * grayMatrix(x - 1, y) + grayMatrix(x - 1, y + 1))
Dim gY As Int = (grayMatrix(x - 1, y + 1) + 2 * grayMatrix(x, y + 1) + grayMatrix(x + 1, y + 1)) - _
(grayMatrix(x - 1, y - 1) + 2 * grayMatrix(x, y - 1) + grayMatrix(x + 1, y - 1))
Dim magnitude As Int = Sqrt(gX * gX + gY * gY)
If magnitude > 255 Then magnitude = 255
' Invert edges for sketch effect
Dim invertedMagnitude As Int = 255 - magnitude
' Apply edge detection result
argb.a = 255 ' Full opacity
argb.r = invertedMagnitude
argb.g = invertedMagnitude
argb.b = invertedMagnitude
edgeBC.SetARGB(x, y, argb)
Next
Next
' Blend edges with a lighter background for sketch effect
Dim sketchBC As BitmapCreator
sketchBC.Initialize(width, height)
For x = 0 To width - 1
For y = 0 To height - 1
' Get the edge pixel
edgeBC.GetARGB(x, y, argb)
' Blend with white (lighter background)
Dim sketchRed As Int = Min(255, argb.r + 50)
Dim sketchGreen As Int = Min(255, argb.g + 50)
Dim sketchBlue As Int = Min(255, argb.b + 50)
' Set the sketch pixel
argb.r = sketchRed
argb.g = sketchGreen
argb.b = sketchBlue
sketchBC.SetARGB(x, y, argb)
Next
Next
' Return the final sketch Bitmap
Return sketchBC.Bitmap
End Sub