English 中文(简体)
科罗ing CG Point of a UIImage
原标题:Coloring CGPoint of a UIImage

我有一张UIImage,我想通过设立欧洲复兴开发银行来改变一些Pixel-colors。 我有用于我需要改变的所有餐厅的CG点。 我如何通过确定欧洲复兴开发银行的价值来改变肤色?

如果不可能改变UIImage pix的颜色,那么利用含有该形象的UIImage语就会是站不住脚的,但我需要做很多事情。

我如何能够这样做?

<>光线>

我为我的问题提出了一个解决办法。 缩略语

-(void)pixelate:(CGPoint)point
{
    CGImageRef inImage = self.drawImage.image.CGImage;
    CGContextRef cgctx = [self createARGBBitmapContextFromImage:inImage];
    if (cgctx == nil) { NSAssert(NO,@"Context shouldn t be nil!"); }

    size_t w = CGImageGetWidth(inImage);
    size_t h = CGImageGetHeight(inImage);
    CGRect rect = {{0,0},{w,h}}; 

    CGContextDrawImage(cgctx, rect, inImage); 

    unsigned char* data = CGBitmapContextGetData(cgctx);
    if (data != nil)
    {
        int offset = 4*((w*round(point.y))+round(point.x));
        data[offset] = 255; //alpha
        data[offset+1] = 255; //red
        data[offset+2] = 0; //green
        data[offset+3] = 0; //blue
    }

    CGImageRef img = CGBitmapContextCreateImage(cgctx);
    UIGraphicsEndImageContext();

    CGContextRelease(cgctx);

    if (data) { free(data); }

    self.drawImage.image = [UIImage imageWithCGImage:img];
}
最佳回答

我为我的问题提出了一个解决办法。 缩略语

-(void)pixelate:(CGPoint)point
{
    CGImageRef inImage = self.drawImage.image.CGImage;
    CGContextRef cgctx = [self createARGBBitmapContextFromImage:inImage];
    if (cgctx == nil) { NSAssert(NO,@"Context shouldn t be nil!"); }

    size_t w = CGImageGetWidth(inImage);
    size_t h = CGImageGetHeight(inImage);
    CGRect rect = {{0,0},{w,h}}; 

    CGContextDrawImage(cgctx, rect, inImage); 

    unsigned char* data = CGBitmapContextGetData(cgctx);
    if (data != nil)
    {
        int offset = 4*((w*round(point.y))+round(point.x));
        data[offset] = 255; //alpha
        data[offset+1] = 255; //red
        data[offset+2] = 0; //green
        data[offset+3] = 0; //blue
    }

    CGImageRef img = CGBitmapContextCreateImage(cgctx);
    UIGraphicsEndImageContext();

    CGContextRelease(cgctx);

    if (data) { free(data); }

    self.drawImage.image = [UIImage imageWithCGImage:img];
}
问题回答

First Imaport following file.>>> Edited....

#import <QuartzCore/QuartzCore.h> 

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef bitmContext = CGBitmapContextCreate(NULL, width, height, 8,bytesPerRow,             colorSpace, kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst);
CGColorSpaceRelease(colorSpace);
CGContextDrawImage(bitmContext, (CGRect){.origin.x = 0.0f, .origin.y = 0.0f, .size.width =     originalWidth, .size.height = originalHeight}, cgImage);

gr reference reference子:

UInt8* data = (UInt8*)CGBitmapContextGetData(bitmContext);

食堂操作:

const size_t bitmapByteCount = bytesPerRow * originalHeight;
for (size_t i = 0; i < bitmapByteCount; i += 4)
{
UInt8 a = data[i];
UInt8 r = data[i + 1];
UInt8 g = data[i + 2];
UInt8 b = data[i + 3];

data[i] = (UInt8)newAlpha
data[i + 1] = (UInt8)newRed;
data[i + 2] = (UInt8)newGreen;
data[i + 3] = (UInt8)newBlue;
}

CGImageRef newImage = CGBitmapContextCreateImage(bitmContext);

Or use this Refrence...

http://www.markj.net/iphone-uiimage-pixel-color/

希望将有助于你们。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签