Note that there are some explanatory texts on larger screens.

plurals
  1. POCore Graphics pointillize effect on CGImage
    text
    copied!<p>So I have been writing a lot of image processing code lately using only core graphics and i have made quite a few working filters that manipulate the colors, apply blends, blurs and stuff like that. But I'm having trouble writing a filter to apply a pointillize effect to an image like this:</p> <p><img src="https://i1130.photobucket.com/albums/m537/sagewashabaugh/PSPointillize.jpg" alt="pointillize"></p> <p>what I'm trying to do is get the color of a pixel and fill an ellipse with that color, looping through the image and doing this every few pixels here is the code:</p> <p>EDIT: here is my new code this time its just drawing a few little circles in the bottom of the image am I doing it right like you said?</p> <pre><code>-(UIImage*)applyFilterWithAmount:(double)amount { CGImageRef inImage = self.CGImage; CFDataRef m_dataRef = CGDataProviderCopyData(CGImageGetDataProvider(inImage)); UInt8* m_pixelBuf = (UInt8*)CFDataGetBytePtr(m_dataRef); int length = CFDataGetLength(m_dataRef); CGContextRef ctx = CGBitmapContextCreate(m_pixelBuf, CGImageGetWidth(inImage), CGImageGetHeight(inImage), CGImageGetBitsPerComponent(inImage), CGImageGetBytesPerRow(inImage), CGImageGetColorSpace(inImage), CGImageGetBitmapInfo(inImage)); int row = 0; int imageWidth = self.size.width; if ((row%imageWidth)==0) { row++; } int col = row%imageWidth; for (int i = 0; i&lt;length; i+=4) { //filterPointillize(m_pixelBuf, i, context); int r = i; int g = i+1; int b = i+2; int red = m_pixelBuf[r]; int green = m_pixelBuf[g]; int blue = m_pixelBuf[b]; CGContextSetRGBFillColor(ctx, red/255, green/255, blue/255, 1.0); CGContextFillEllipseInRect(ctx, CGRectMake(col, row, amount, amount)); } CGImageRef imageRef = CGBitmapContextCreateImage(ctx); CGContextRelease(ctx); UIImage* finalImage = [UIImage imageWithCGImage:imageRef]; CGImageRelease(imageRef); CFRelease(m_dataRef); return finalImage; </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload