#Region Project Attributes
#ApplicationLabel: Pixel
#Version: 1.0.0
'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
#iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
#iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
#PlistExtra: <key>UIViewControllerBasedStatusBarAppearance</key><false/>
#End Region
Sub Process_Globals
Public App As Application
Public NavControl As NavigationController
Private Page1 As Page
Private iv As ImageView
Dim c As Canvas
Private sw,sh As Int
Private j As Int
Private pcolor,cl As Int
Private btn As Button
Private bmp As Bitmap
Private scw, sch As Float
End Sub
Private Sub Application_Start (Nav As NavigationController)
Dim no As NativeObject = App
no.RunMethod("setStatusBarHidden:animated:", Array(True, False))
NavControl = Nav
Page1.Initialize("Page1")
Page1.Title = "Page 1"
NavControl.NavigationBarVisible = False
NavControl.ShowPage(Page1)
sw=GetDeviceLayoutValues.Width
sh=GetDeviceLayoutValues.Height
btn.Initialize("btn",btn.STYLE_SYSTEM)
btn.Color=Colors.LightGray
btn.Text="Click"
Page1.RootPanel.AddView(btn,40*sw/100,70*sh/100,20*sw/100,10*sh/100)
iv.Initialize("iv")
Page1.RootPanel.AddView(iv,0,0,sw,sh)
c.Initialize(iv)
cl=255
For j=0 To sh
cl=255-(j mod 256)
c.DrawLine(0,j,sw,j,Colors.ARGB(255 ,cl , cl, cl ),1)
Next
iv.Bitmap=c.CreateBitmap
bmp=iv.Bitmap
Log("Bitmap size = "&bmp.Width&" "&bmp.Height)
Log("imageview size = "&iv.Width&" "&iv.Height)
btn.BringToFront
scw=bmp.Width/iv.Width
sch=bmp.Height/iv.Height
End Sub
Sub GetARGB(Clr As Int) As Int()
Dim res(4) As Int
res(0) = Bit.UnsignedShiftRight(Bit.And(Clr, 0xff000000), 24)
res(1) = Bit.UnsignedShiftRight(Bit.And(Clr, 0xff0000), 16)
res(2) = Bit.UnsignedShiftRight(Bit.And(Clr, 0xff00), 8)
res(3) = Bit.And(Clr, 0xff)
Return res
End Sub
Sub GetPixelColor(Bitm As Bitmap, x As Int, y As Int) As Int
Dim NativeMe As NativeObject = Me
Dim UIColor As Object = NativeMe.RunMethod("GetPixelColor:::", Array (Bitm,x*scw,y*sch))
Return NativeMe.UIColorToColor(UIColor)
End Sub
Sub btn_Click
Dim argb() As Int
Log("Height Color Value A R G B")
For j=0 To sh
pcolor=GetPixelColor(iv.Bitmap,100,j)
argb = GetARGB(pcolor)
Log(j&" "&pcolor&" "&argb(0)&" "&argb(1)&" "&argb(2)&" "&argb(3))
c.DrawLine(0,j,10,j,Colors.ARGB(255 ,j , 255, 255 ),1)
Next
c.Refresh
End Sub
#If OBJC
- (UIColor *)GetPixelColor:(UIImage *)bitmap :(int)x :(int)y {
CFDataRef pixelData = CGDataProviderCopyData(CGImageGetDataProvider(bitmap.CGImage));
const UInt8* data = CFDataGetBytePtr(pixelData);
int pixelInfo = ((bitmap.size.width * y) + x ) * 4;
UInt8 red = data[pixelInfo];
UInt8 green = data[(pixelInfo + 1)];
UInt8 blue = data[pixelInfo + 2];
UInt8 alpha = data[pixelInfo + 3];
CFRelease(pixelData);
return [UIColor colorWithRed:red/255.0f green:green/255.0f blue:blue/255.0f alpha:alpha/255.0f];
}
#End If