ios - Get screen (View) black pixels fast and efficiently -
i searching in asked questions, of them describing how pixel colour of uiimage (which did not best solution in case).
i want check pixels of screen , number of black pixels or black (very dark) pixels. know how check how dark single pixel - checking if rgb (255) values of pixel selected less 10 or something. don't know how check full amount of pixels of uiimage in fast , efficient way.
so want check pixels of screen , number of them. later in app again , compare amount of black pixels before , after events.
is there fast solution them?
it "snapshot" searching if else have similar situation. took snapshot:
uigraphicsbeginimagecontext(self.view.bounds.size); [self.view.layer renderincontext:uigraphicsgetcurrentcontext()]; uiimage *original = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); and searched black pixels in it:
width = (int)original.size.width; height = (int)original.size.height; cfdataref imagedata = cgdataprovidercopydata(cgimagegetdataprovider(original.cgimage)); const uint8 *pixels = cfdatagetbyteptr(imagedata); uint8 blackthreshold = 5; // or value close 0 - dark pixels int bytesperpixel = 4; for(int x = 0; x < width; x++) { for(int y = 0; y < height; y++) { int pixelstartindex = (x + (y * width)) * bytesperpixel; uint8 redvalue= pixels[pixelstartindex]; uint8 greenvalue = pixels[pixelstartindex + 1]; uint8 bluevalue = pixels[pixelstartindex + 2]; if(redvalue < blackthreshold && bluevalue < blackthreshold && greenvalue < blackthreshold) { /// count black pixels ore else want } } }
Comments
Post a Comment