{"id":460,"date":"2012-07-31T09:25:21","date_gmt":"2012-07-31T06:25:21","guid":{"rendered":"http:\/\/ilya2606.ru\/?p=460"},"modified":"2012-08-02T12:23:27","modified_gmt":"2012-08-02T09:23:27","slug":"%d0%bf%d0%b5%d1%80%d0%b5%d0%b2%d0%be%d0%b4-%d0%b8%d0%b7%d0%be%d0%b1%d1%80%d0%b0%d0%b6%d0%b5%d0%bd%d0%b8%d1%8f-%d0%b2-%d1%87%d0%b5%d1%80%d0%bd%d0%be-%d0%b1%d0%b5%d0%bb%d0%be%d0%b5","status":"publish","type":"post","link":"http:\/\/ilya2606.ru\/?p=460","title":{"rendered":"\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432 \u0447\u0435\u0440\u043d\u043e-\u0431\u0435\u043b\u043e\u0435"},"content":{"rendered":"<p><a href=\"http:\/\/ilya2606.ru\/wp-content\/uploads\/2012\/07\/kwarc61tc310d.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-463\" title=\"\u0427\u0411\" src=\"http:\/\/ilya2606.ru\/wp-content\/uploads\/2012\/07\/kwarc61tc310d-300x209.jpg\" alt=\"\" width=\"300\" height=\"209\" srcset=\"http:\/\/ilya2606.ru\/wp-content\/uploads\/2012\/07\/kwarc61tc310d-300x209.jpg 300w, http:\/\/ilya2606.ru\/wp-content\/uploads\/2012\/07\/kwarc61tc310d.jpg 500w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0432\u0430\u043c \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u0446\u0432\u0435\u0442\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u0447\u0435\u0440\u043d\u043e-\u0431\u0435\u043b\u043e\u0435.<\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 convertToGrayscale:<\/p>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<p>&#8211; source: \u0418\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u0446\u0432\u0435\u0442\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u00a0UIImage<\/p>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435:<\/p>\n<p>&#8211; \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u00a0UIImage<\/p>\n<p><!--more--><\/p>\n<p>typedef enum {<\/p>\n<p style=\"padding-left: 30px;\"><code> ALPHA = 0,<br \/>\nBLUE = 1,<br \/>\nGREEN = 2,<br \/>\nRED = 3<\/code><\/p>\n<p><code><\/code>} PIXELS;<\/p>\n<p>&nbsp;<\/p>\n<p>&#8211; (UIImage *)convertToGrayscale:(UIImage *)source {<\/p>\n<p style=\"padding-left: 30px;\">CGSize size = [source size];<br \/>\nint width = size.width;<br \/>\nint height = size.height;<\/p>\n<p style=\"padding-left: 30px;\">\/\/ \u043f\u0438\u043a\u0441\u0435\u043b\u0438 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u044b \u0432 \u044d\u0442\u043e\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u0435<br \/>\nuint32_t *pixels = (uint32_t *) malloc(width * height * sizeof(uint32_t));<\/p>\n<p style=\"padding-left: 30px;\">\/\/ \u0447\u0438\u0441\u0442\u0438\u043c \u043f\u0438\u043a\u0441\u0435\u043b\u0438 \u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0441\u0442\u0438<br \/>\nmemset(pixels, 0, width * height * sizeof(uint32_t));<\/p>\n<p style=\"padding-left: 30px;\">\/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0446\u0432\u0435\u0442\u043e\u0432\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e<br \/>\nCGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();<\/p>\n<p style=\"padding-left: 30px;\">\/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0432 \u0441\u0445\u0435\u043c\u0435 RGBA<br \/>\nCGContextRef context = CGBitmapContextCreate(pixels, width, height, 8, width * sizeof(uint32_t), colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedLast);<\/p>\n<p style=\"padding-left: 30px;\">\/\/ \u0440\u0438\u0441\u0443\u0435\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0443 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439<br \/>\nCGContextDrawImage(context, CGRectMake(0, 0, width, height), source.CGImage);<\/p>\n<p style=\"padding-left: 30px;\">\/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0439\u0442\u0438\u0441\u044c \u043f\u043e \u0432\u0441\u0435\u043c \u043f\u0438\u043a\u0441\u0435\u043b\u044f\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f<br \/>\nfor(int y = 0; y &lt; height; y++) {<\/p>\n<p style=\"padding-left: 60px;\">for(int x = 0; x &lt; width; x++) {<\/p>\n<p style=\"padding-left: 90px;\">uint8_t *rgbaPixel = (uint8_t *) &amp;pixels[y * width + x];<\/p>\n<p style=\"padding-left: 90px;\">\/\/ \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432 \u0447\u0435\u0440\u043d\u043e-\u0431\u0435\u043b\u044b\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u043c\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0438\u0437 \u0412\u0438\u043a\u0438: http:\/\/en.wikipedia.org\/wiki\/Grayscale#Converting_color_to_grayscale<br \/>\nuint32_t gray = 0.3 * rgbaPixel[RED] + 0.59 * rgbaPixel[GREEN] + 0.11 * rgbaPixel[BLUE];<\/p>\n<p style=\"padding-left: 90px;\">\/\/ \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043f\u0438\u043a\u0441\u0435\u043b\u044c \u0432 \u0441\u0435\u0440\u044b\u0445 \u0442\u043e\u043d\u0430\u0445<br \/>\nrgbaPixel[RED] = gray;<br \/>\nrgbaPixel[GREEN] = gray;<br \/>\nrgbaPixel[BLUE] = gray;<\/p>\n<p style=\"padding-left: 60px;\">}<\/p>\n<p style=\"padding-left: 30px;\">}<\/p>\n<p style=\"padding-left: 30px;\">\/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c CGImageRef, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439<br \/>\nCGImageRef image = CGBitmapContextCreateImage(context);<\/p>\n<p style=\"padding-left: 30px;\">\/\/ \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u043c \u043f\u0430\u043c\u044f\u0442\u044c<br \/>\nCGContextRelease(context);<br \/>\nCGColorSpaceRelease(colorSpace);<br \/>\nfree(pixels);<\/p>\n<p style=\"padding-left: 30px;\">\/\/ \u0434\u0435\u043b\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 UIImage \u0434\u043b\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430<br \/>\nUIImage *resultUIImage = [UIImage imageWithCGImage:image];<\/p>\n<p style=\"padding-left: 30px;\">\/\/\u00a0\u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u043c \u043f\u0430\u043c\u044f\u0442\u044c<br \/>\nCGImageRelease(image);<\/p>\n<p style=\"padding-left: 30px;\">\/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0447\u0435\u0440\u043d\u043e-\u0431\u0435\u043b\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435<br \/>\nreturn resultUIImage;<\/p>\n<p>}<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><div align=\"right\"><div class=\"sharexyWidgetNoindexUniqueClassName\"><div id=\"shr_56695431\"><\/div><\/div><\/div><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>&nbsp; \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0432\u0430\u043c \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u0446\u0432\u0435\u0442\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u0447\u0435\u0440\u043d\u043e-\u0431\u0435\u043b\u043e\u0435. \u041c\u0435\u0442\u043e\u0434 convertToGrayscale: \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b: &#8211; source: \u0418\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u0446\u0432\u0435\u0442\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u00a0UIImage \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435: &#8211; \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u00a0UIImage<\/p>\n<div align=\"right\">\n<div class=\"sharexyWidgetNoindexUniqueClassName\">\n<div id=\"shr_56695431\"><\/div>\n<\/div>\n<\/div>\n<p><!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,6],"tags":[],"_links":{"self":[{"href":"http:\/\/ilya2606.ru\/index.php?rest_route=\/wp\/v2\/posts\/460"}],"collection":[{"href":"http:\/\/ilya2606.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ilya2606.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ilya2606.ru\/index.php?rest_route=\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"http:\/\/ilya2606.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=460"}],"version-history":[{"count":8,"href":"http:\/\/ilya2606.ru\/index.php?rest_route=\/wp\/v2\/posts\/460\/revisions"}],"predecessor-version":[{"id":467,"href":"http:\/\/ilya2606.ru\/index.php?rest_route=\/wp\/v2\/posts\/460\/revisions\/467"}],"wp:attachment":[{"href":"http:\/\/ilya2606.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ilya2606.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=460"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ilya2606.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}