Search Results

Search found 114 results on 5 pages for 'cgimage'.

Page 4/5 | < Previous Page | 1 2 3 4 5  | Next Page >

  • Creating a mask from a graphics context

    - by Magic Bullet Dave
    I want to be able to create a greyscale image with no alpha from a png in the app bundle. This works, and I get an image created: // Create graphics context the size of the overlapping rectangle UIGraphicsBeginImageContext(rectangleOfOverlap.size); CGContextRef ctx = UIGraphicsGetCurrentContext(); // More stuff CGContextDrawImage(ctx, drawRect2, [UIImage imageNamed:@"Image 01.png"].CGImage); // Create the new UIImage from the context UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); However the resulting image is 32 bits per pixel and has an alpha channel, so when I use CGCreateImageWithMask it doesn't work. I've tried creating a bitmap context thus: CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray(); CGContextRef ctx =CGBitmapContextCreate(nil, rectangleOfOverlap.size.width, rectangleOfOverlap.size.height, 8, rectangleOfOverlap.size.width , colorSpace, kCGImageAlphaNone); UIGraphicsGetImageFromCurrentImageContext returns zero and the resulting image is not created. Am I doing something dumb here? Any help would be greatly appreciated. Regards Dave

    Read the article

  • Need example of how to create/manipulate image pixel data with iPhone SDK

    - by whiskeyspider
    Looking for a simple example or link to a tutorial. Say I have a bunch of values stored in an array. I would like to create an image and update the image data from my array. Assume the array values are intensity data and will be updating a grayscale image. Assume the array values are between 0 and 255 -- or that I will convert it to that range. This is not for purposes of animation. Rather the image would be updated based on user interaction. This is something I know how to do well in Java, but am very new to iPhone programming. I've googled some information about CGImage and UIImage -- but am confused as to where to start. Any help would be appreciated.

    Read the article

  • [CA_COLOR_OPAQUE] things that make a layer non-opaque. scaled CAGradientLayer?

    - by mahal tertin
    i spent some time with the environment variable CA_COLOR_OPAQUE = 1 and have my findings to share. things that make a CALayer non-opaque (slow, more memory, ...): * contents with alpha (like an NSImage with an icon) * NSImage/CGImage from a pdf as contents (even when the pdf does not contain any alpha and opaque=YES) * backgroundColor = nil * CATextLayer with text in a (because it is contents with alpha) * rounded corners? maybe/sometimes * masksToBounds? not necessarily as we scale most of tree with CATransform3DScale on sublayerTransform i found also these rather irritating non-opaque: * CAGradientLayer that is somewhere down in this scaled tree (even when set all the gradient colors without alpha) * edgeAntialiasingMask != 0 of a layer that is somewhere down in this scaled tree the last two do not make sense to me. why should it be non opaque? what do i see? if anyone has any thoughts on these findings, i'm happy to learn as i couldn't find such a list yet.

    Read the article

  • iPhone: How can you draw a piece of an image

    - by Mark
    Code sample - (void)drawRect:(CGRect)rect { [super drawRect:rect]; CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); CGContextTranslateCTM(context, 0, self.frame.size.height); CGContextScaleCTM(context, 1.0, -1.0); CGContextDrawImage(context, CGRectMake(0.0, 0.0, self.frame.size.width, self.frame.size.height), [UIImage imageNamed:@"sample.png"].CGImage); CGContextRestoreGState(context); } ================ I would like to copy a certain rect within an image to the context, so not the entire image is drawn but just a piece of the image. Does anyone have a solution for this? I can't find anything on google nor the documentation. I know there are alternatives like: 1. Create a UIView with clipping and then just position the UIImageView within it. 2. Create the UIImageView within the UIScrollView and use content offset. But I think those are lame...

    Read the article

  • Why my image is up side down?

    - by Tattat
    This is my drawInContext method: UIImage *img = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"myImage" ofType:@"png"]]; CGRect cropRect = CGRectMake(0, 0, 175, 175); CGImageRef imageRef = CGImageCreateWithImageInRect([img CGImage], cropRect); CGRect imageRect; imageRect.origin = CGPointMake(0, 0); imageRect.size = CGSizeMake(175, 175); CGContextDrawImage(UIGraphicsGetCurrentContext(), imageRect, imageRef); CGImageRelease(imageRef); My image is upside down, how can I change it? What's wrong with my code? How can I change the image become normal?? thx .

    Read the article

  • Rendering Texture Quad to Screen or FBO (OpenGL ES)

    - by Usman.3D
    I need to render the texture on the iOS device's screen or a render-to-texture frame buffer object. But it does not show any texture. It's all black. (I am loading texture with image myself for testing purpose) //Load texture data UIImage *image=[UIImage imageNamed:@"textureImage.png"]; GLuint width = FRAME_WIDTH; GLuint height = FRAME_HEIGHT; //Create context void *imageData = malloc(height * width * 4); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef context = CGBitmapContextCreate(imageData, width, height, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); CGColorSpaceRelease(colorSpace); //Prepare image CGContextClearRect(context, CGRectMake(0, 0, width, height)); CGContextDrawImage(context, CGRectMake(0, 0, width, height), image.CGImage); glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); Simple Texture Quad drawing code mentioned here //Bind Texture, Bind render-to-texture FBO and then draw the quad const float quadPositions[] = { 1.0, 1.0, 0.0, -1.0, 1.0, 0.0, -1.0, -1.0, 0.0, -1.0, -1.0, 0.0, 1.0, -1.0, 0.0, 1.0, 1.0, 0.0 }; const float quadTexcoords[] = { 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0 }; // stop using VBO glBindBuffer(GL_ARRAY_BUFFER, 0); // setup buffer offsets glVertexAttribPointer(ATTRIB_VERTEX, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), quadPositions); glVertexAttribPointer(ATTRIB_TEXCOORD0, 2, GL_FLOAT, GL_FALSE, 2*sizeof(float), quadTexcoords); // ensure the proper arrays are enabled glEnableVertexAttribArray(ATTRIB_VERTEX); glEnableVertexAttribArray(ATTRIB_TEXCOORD0); //Bind Texture and render-to-texture FBO. glBindTexture(GL_TEXTURE_2D, GLid); //Actually wanted to render it to render-to-texture FBO, but now testing directly on default FBO. //glBindFramebuffer(GL_FRAMEBUFFER, textureFBO[pixelBuffernum]); // draw glDrawArrays(GL_TRIANGLES, 0, 2*3); What am I doing wrong in this code? P.S. I'm not familiar with shaders yet, so it is difficult for me to make use of them right now.

    Read the article

  • iPhone Image Processing--matrix convolution

    - by James
    I am implementing a matrix convolution blur on the iPhone. The following code converts the UIImage supplied as an argument of the blur function into a CGImageRef, and then stores the RGBA values in a standard C char array. CGImageRef imageRef = imgRef.CGImage; int width = imgRef.size.width; int height = imgRef.size.height; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); unsigned char *pixels = malloc((height) * (width) * 4); NSUInteger bytesPerPixel = 4; NSUInteger bytesPerRow = bytesPerPixel * (width); NSUInteger bitsPerComponent = 8; CGContextRef context = CGBitmapContextCreate(pixels, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); CGContextRelease(context); Then the pixels values stored in the pixels array are convolved, and stored in another array. unsigned char *results = malloc((height) * (width) * 4); Finally, these augmented pixel values are changed back into a CGImageRef, converted to a UIImage, and the returned at the end of the function with the following code. context = CGBitmapContextCreate(results, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); CGImageRef finalImage = CGBitmapContextCreateImage(context); UIImage *newImage = [UIImage imageWithCGImage:CGBitmapContextCreateImage(context)]; CGImageRelease(finalImage); NSLog(@"edges found"); free(results); free(pixels); CGColorSpaceRelease(colorSpace); return newImage; This works perfectly, once. Then, once the image is put through the filter again, very odd, unprecedented pixel values representing input pixel values that don't exist, are returned. Is there any reason why this should work the first time, but then not afterward? Beneath is the entirety of the function. -(UIImage*) blur:(UIImage*)imgRef { CGImageRef imageRef = imgRef.CGImage; int width = imgRef.size.width; int height = imgRef.size.height; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); unsigned char *pixels = malloc((height) * (width) * 4); NSUInteger bytesPerPixel = 4; NSUInteger bytesPerRow = bytesPerPixel * (width); NSUInteger bitsPerComponent = 8; CGContextRef context = CGBitmapContextCreate(pixels, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); CGContextRelease(context); height = imgRef.size.height; width = imgRef.size.width; float matrix[] = {0,0,0,0,1,0,0,0,0}; float divisor = 1; float shift = 0; unsigned char *results = malloc((height) * (width) * 4); for(int y = 1; y < height; y++){ for(int x = 1; x < width; x++){ float red = 0; float green = 0; float blue = 0; int multiplier=1; if(y>0 && x>0){ int index = (y-1)*width + x; red = matrix[0]*multiplier*(float)pixels[4*(index-1)] + matrix[1]*multiplier*(float)pixels[4*(index)] + matrix[2]*multiplier*(float)pixels[4*(index+1)]; green = matrix[0]*multiplier*(float)pixels[4*(index-1)+1] + matrix[1]*multiplier*(float)pixels[4*(index)+1] + matrix[2]*multiplier*(float)pixels[4*(index+1)+1]; blue = matrix[0]*multiplier*(float)pixels[4*(index-1)+2] + matrix[1]*multiplier*(float)pixels[4*(index)+2] + matrix[2]*multiplier*(float)pixels[4*(index+1)+2]; index = (y)*width + x; red = red+ matrix[3]*multiplier*(float)pixels[4*(index-1)] + matrix[4]*multiplier*(float)pixels[4*(index)] + matrix[5]*multiplier*(float)pixels[4*(index+1)]; green = green + matrix[3]*multiplier*(float)pixels[4*(index-1)+1] + matrix[4]*multiplier*(float)pixels[4*(index)+1] + matrix[5]*multiplier*(float)pixels[4*(index+1)+1]; blue = blue + matrix[3]*multiplier*(float)pixels[4*(index-1)+2] + matrix[4]*multiplier*(float)pixels[4*(index)+2] + matrix[5]*multiplier*(float)pixels[4*(index+1)+2]; index = (y+1)*width + x; red = red+ matrix[6]*multiplier*(float)pixels[4*(index-1)] + matrix[7]*multiplier*(float)pixels[4*(index)] + matrix[8]*multiplier*(float)pixels[4*(index+1)]; green = green + matrix[6]*multiplier*(float)pixels[4*(index-1)+1] + matrix[7]*multiplier*(float)pixels[4*(index)+1] + matrix[8]*multiplier*(float)pixels[4*(index+1)+1]; blue = blue + matrix[6]*multiplier*(float)pixels[4*(index-1)+2] + matrix[7]*multiplier*(float)pixels[4*(index)+2] + matrix[8]*multiplier*(float)pixels[4*(index+1)+2]; red = red/divisor+shift; green = green/divisor+shift; blue = blue/divisor+shift; if(red<0){ red=0; } if(green<0){ green=0; } if(blue<0){ blue=0; } if(red>255){ red=255; } if(green>255){ green=255; } if(blue>255){ blue=255; } int realPos = 4*(y*imgRef.size.width + x); results[realPos] = red; results[realPos + 1] = green; results[realPos + 2] = blue; results[realPos + 3] = 1; }else { int realPos = 4*((y)*(imgRef.size.width) + (x)); results[realPos] = 0; results[realPos + 1] = 0; results[realPos + 2] = 0; results[realPos + 3] = 1; } } } context = CGBitmapContextCreate(results, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); CGImageRef finalImage = CGBitmapContextCreateImage(context); UIImage *newImage = [UIImage imageWithCGImage:CGBitmapContextCreateImage(context)]; CGImageRelease(finalImage); free(results); free(pixels); CGColorSpaceRelease(colorSpace); return newImage;} THANKS!!!

    Read the article

  • CGBitmapContextCreate on the iPhone/iPad

    - by toastie
    Hello, I have a method that needs to parse through a bunch of large PNG images pixel by pixel (the PNGs are 600x600 pixels each). It seems to work great on the Simulator, but on the device (iPad), i get an EXC_BAD_ACCESS in some internal memory copying function. It seems the size is the culprit because if I try it on smaller images, everything seems to work. Here's the memory related meat of method below. + (CGRect) getAlphaBoundsForUImage: (UIImage*) image { CGImageRef imageRef = [image CGImage]; NSUInteger width = CGImageGetWidth(imageRef); NSUInteger height = CGImageGetHeight(imageRef); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); unsigned char *rawData = malloc(height * width * 4); memset(rawData,0,height * width * 4); NSUInteger bytesPerPixel = 4; NSUInteger bytesPerRow = bytesPerPixel * width; NSUInteger bitsPerComponent = 8; CGContextRef context = CGBitmapContextCreate(rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); CGColorSpaceRelease(colorSpace); CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); CGContextRelease(context); /* non-memory related stuff */ free(rawData); When I run this on a bunch of images, it runs 12 times and then craps out, while on the simulator it runs no problem. Do you guys have any ideas?

    Read the article

  • how to change UITabbar selected color?

    - by RAGOpoR
    according to this post for now, Is apple will also reject this code? and how to implement what apple will approve? @interface UITabBar (ColorExtensions) - (void)recolorItemsWithColor:(UIColor *)color shadowColor:(UIColor *)shadowColor shadowOffset:(CGSize)shadowOffset shadowBlur:(CGFloat)shadowBlur; @end @interface UITabBarItem (Private) @property(retain, nonatomic) UIImage *selectedImage; - (void)_updateView; @end @implementation UITabBar (ColorExtensions) - (void)recolorItemsWithColor:(UIColor *)color shadowColor:(UIColor *)shadowColor shadowOffset:(CGSize)shadowOffset shadowBlur:(CGFloat)shadowBlur { CGColorRef cgColor = [color CGColor]; CGColorRef cgShadowColor = [shadowColor CGColor]; for (UITabBarItem *item in [self items]) if ([item respondsToSelector:@selector(selectedImage)] && [item respondsToSelector:@selector(setSelectedImage:)] && [item respondsToSelector:@selector(_updateView)]) { CGRect contextRect; contextRect.origin.x = 0.0f; contextRect.origin.y = 0.0f; contextRect.size = [[item selectedImage] size]; // Retrieve source image and begin image context UIImage *itemImage = [item image]; CGSize itemImageSize = [itemImage size]; CGPoint itemImagePosition; itemImagePosition.x = ceilf((contextRect.size.width - itemImageSize.width) / 2); itemImagePosition.y = ceilf((contextRect.size.height - itemImageSize.height) / 2); UIGraphicsBeginImageContext(contextRect.size); CGContextRef c = UIGraphicsGetCurrentContext(); // Setup shadow CGContextSetShadowWithColor(c, shadowOffset, shadowBlur, cgShadowColor); // Setup transparency layer and clip to mask CGContextBeginTransparencyLayer(c, NULL); CGContextScaleCTM(c, 1.0, -1.0); CGContextClipToMask(c, CGRectMake(itemImagePosition.x, -itemImagePosition.y, itemImageSize.width, -itemImageSize.height), [itemImage CGImage]); // Fill and end the transparency layer CGContextSetFillColorWithColor(c, cgColor); contextRect.size.height = -contextRect.size.height; CGContextFillRect(c, contextRect); CGContextEndTransparencyLayer(c); // Set selected image and end context [item setSelectedImage:UIGraphicsGetImageFromCurrentImageContext()]; UIGraphicsEndImageContext(); // Update the view [item _updateView]; } } @end

    Read the article

  • Blind down animation on CALayer using a mask

    - by dgjones346
    Hi there, I want to create a "blind down" effect on an image so the image "blinds down" and appears. Sort of like this JavaScript transition: http://wiki.github.com/madrobby/scriptaculous/effect-blinddown The mask is setup correctly because if I manually change it's position it hides and reveals the image behind it, but it doesn't animate! It just ends up in the animates final position and you never see it actual blind. Please help! Maybe this isn't the best way to achieve a blind down effect? // create a new layer CALayer *numberLayer = [[CALayer alloc] init]; // render the number "7" on the layer UIImage *image = [UIImage imageNamed:@"number-7.png"]; numberLayer.contents = (id) [image CGImage]; numberLayer.bounds = CGRectMake(0, 0, image.size.width, image.size.height); // width and height are 50 numberLayer.position = position; // create a new mask that is 50x50 the size of the image CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; CGMutablePathRef path = CGPathCreateMutable(); CGPathAddRect(path, nil, CGRectMake(0, 0, 50, 50)); [maskLayer setPath:path]; [maskLayer setFillColor:[[UIColor whiteColor] CGColor]]; [theLayer setMask:maskLayer]; [maskLayer setPosition:CGPointMake(0, 0)]; // place the mask over the image [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:3.0]; [maskLayer setPosition:CGPointMake(0, 50)]; // slide mask off the image // this should shift the blind away in an animation // but it doesn't animate [UIView commitAnimations]; [maskLayer release]; [boardLayer addSublayer:numberLayer]; [numberLayer release];

    Read the article

  • CGImageCreateWithMask with an image as a mask

    - by Peyman
    Hi I am trying to use an image (painted as Core Graphics) to create a mask. What I am doing is this 1. creating a Core Graphics path CGContextSaveGState(context); CGContextBeginPath(context); CGContextMoveToPoint(context,circleCenter.x,circleCenter.y); //CGContextSetAllowsAntialiasing(myBitmapContext, YES); CGContextAddArc(context,circleCenter.x, circleCenter.y,circleRadius,startingAngle, endingAngle, 0); // 0 is counterclockwise CGContextClosePath(context); CGContextSetRGBStrokeColor(context,1.0,0.0,0.0,1.0); CGContextSetRGBFillColor(context,1.0,0.0,0.0,0.2); CGContextDrawPath(context, kCGPathFillStroke); 2. then I'm saving the context that has the path just painted CGImageRef pacmanImage = CGBitmapContextCreateImage (context); 3. restoring the context CGContextRestoreGState(context); CGContextSaveGState(context); 4. creating a 1 bit mask (which will provide the black-white mask) bitsPerComponent = 1; bitsPerPixel = bitsPerComponent * 1 ; bytesPerRow = (CGImageGetWidth(imgToMaskRef) * bitsPerPixel); mask = CGImageCreate(CGImageGetWidth(imgToMaskRef), CGImageGetHeight(imgToMaskRef), bitsPerComponent, bitsPerPixel, bytesPerRow, greyColorSpace, kCGImageAlphaNone, CGImageGetDataProvider(pacmanImage), NULL, //decode YES, //shouldInterpolate kCGRenderingIntentDefault); 5. masking the imgToMaskRef (which is a CGImageRef imgToMaskRef =imgToMask.CGImage;) with the mask just created imageMaskedWithImage = CGImageCreateWithMask(imgToMaskRef, mask); CGContextDrawImage(context,imgRectBox, imageMaskedWithImage); CGImageRef maskedImageFinal = CGBitmapContextCreateImage (context); returning the maskedImageFinal to the caller of this method (as wheelChoiceMadeState, which is a CGImageRef) who then updates the CALayer contents property with the image theLayer.contents = (id) wheelChoiceMadeState; the problem I am seeing is that the mask does not work properly and looks very strange indeed. I get strange patterns across the path painted by the Core Graphics. My hunch is there is something with CGImageGetDataProvider() but I am not sure. Any help would be appreciated thank you

    Read the article

  • How to get skin tone color pixel in iPhone?

    - by aman-gupta
    Hi In my application I m using following way to get red pixel in a image // // PixelsAccessAppDelegate.h // PixelsAccess // // Created by Fortune1 on 14/04/10. // Copyright MyCompanyName 2010. All rights reserved. // import @class clsPixelAccess; NSUInteger numberOfRedPixels; NSUInteger numberOfRedPixels1; NSUInteger numberOfRedPixels2; NSUInteger numberOfRedPixels3; NSUInteger numberOfRedPixels4; NSUInteger numberOfRedPixels5; NSUInteger numberOfRedPixels6; NSUInteger numberOfRedPixels7; NSUInteger numberOfRedPixels8; NSUInteger numberOfRedPixels9; NSUInteger numberOfRedPixels10; NSUInteger numberOfRedPixels11; NSUInteger numberOfRedPixels12; NSUInteger numberOfRedPixels13; NSUInteger numberOfRedPixels14; NSUInteger numberOfRedPixels15; NSUInteger numberOfRedPixels16; NSUInteger numberOfRedPixels17; NSUInteger numberOfRedPixels18; NSUInteger numberOfRedPixels19; NSUInteger numberOfRedPixels20; NSUInteger numberOfRedPixels21; NSUInteger numberOfRedPixels22; NSUInteger numberOfRedPixels23; NSUInteger numberOfRedPixels24; NSUInteger numberOfRedPixels25; NSUInteger numberOfRedPixels26; NSUInteger numberOfRedPixels27; NSUInteger numberOfRedPixels28; NSUInteger numberOfRedPixels29; NSUInteger numberOfRedPixels30; NSUInteger numberOfRedPixels31; @interface PixelsAccessAppDelegate : NSObject { UIWindow *window; clsPixelAccess *obj; } @property (nonatomic, retain) IBOutlet UIWindow *window; -(IBAction)processImage:(id)sender; @end //////////////////// // // PixelsAccessAppDelegate.m // PixelsAccess // // Created by Fortune1 on 14/04/10. // Copyright MyCompanyName 2010. All rights reserved. // import "PixelsAccessAppDelegate.h" import "clsPixelAccess.h" @implementation PixelsAccessAppDelegate @synthesize window; (IBAction)processImage:(id)sender { NSUInteger retVal; obj = [[clsPixelAccess alloc] init]; NSInteger imageSend =[obj processImage1:[UIImage imageNamed:@"s.jpg"]]; NSInteger iamgeCall =[obj getPixelData:retVal]; NSUInteger *numberOfRedPixels = retVal; //lblPixelCount.text = [NSString stringWithFormat: @"There are %d red pixels in the image", numberOfRedPixels]; } (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after application launch [window makeKeyAndVisible]; } (void)dealloc { [window release]; [super dealloc]; } @end /////////////// // // clsPixelsAccess.h // PixelsAccess // // Created by Fortune1 on 14/04/10. // Copyright 2010 MyCompanyName. All rights reserved. // import @interface clsPixelAccess : NSObject { } -(NSInteger) processImage1: (UIImage*) image; -(NSInteger)getPixelData:(NSUInteger *)pixelCount; @end ///////// // // clsPixelsAccess.m // PixelsAccess // // Created by Fortune1 on 14/04/10. // Copyright 2010 MyCompanyName. All rights reserved. // import "clsPixelAccess.h" import "PixelsAccessAppDelegate.h" @implementation clsPixelAccess struct pixel { //unsigned char r, g, b,a; Byte r, g, b, a; int count; }; -(NSInteger)getPixelData:(NSUInteger *)pixelCount { *pixelCount =numberOfRedPixels; return 1; } // Process the image and return the number of pure red pixels in it. (NSInteger) processImage1: (UIImage*) image { // Allocate a buffer big enough to hold all the pixels struct pixel* pixels = (struct pixel*) calloc(1, image.size.width * image.size.height * sizeof(struct pixel)); if (pixels != nil) { // Create a new bitmap CGContextRef context = CGBitmapContextCreate( (void*) pixels, image.size.width, image.size.height, 8, image.size.width * 4, CGImageGetColorSpace(image.CGImage), kCGImageAlphaPremultipliedLast ); //NSLog(@"1=%d, 2=%d, 3=%d", CGImageGetBitsPerComponent(image), CGImageGetBitsPerPixel(image),CGImageGetBytesPerRow(image)); if (context != NULL) { // Draw the image in the bitmap CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, image.size.width, image.size.height), image.CGImage); NSUInteger numberOfPixels = image.size.width * image.size.height; NSMutableArray *numberOfPixelsArray = [[[NSMutableArray alloc] initWithCapacity:numberOfPixelsArray] autorelease]; NSLog( @"Pixel data %d", numberOfPixelsArray); /* NSMatrix *newMatrix = [[NSMatrix alloc] initWithFrame:NSMakeRect(138.0f, 85.0f, 0.0f, 0.0f) mode:NSRadioModeMatrix prototype:prototypeButtonCell numberOfRows: numberOfColumns:]; */ while (numberOfPixels &gt; 0) { if (pixels-&gt;r &gt; 0 &amp;&amp; pixels-&gt;r &lt;= 7) { numberOfRedPixels++; } NSLog( @"Red pixel data %d",numberOfRedPixels); if (pixels-&gt;r &gt;= 8 &amp;&amp; pixels-&gt;r &lt;= 15) { numberOfRedPixels1++; } NSLog( @"Red pixel data1 %d",numberOfRedPixels1); if (pixels-&gt;r &gt;= 16 &amp;&amp; pixels-&gt;r &lt;=23 ) { numberOfRedPixels2++; } NSLog( @"Red pixel data2 %d",numberOfRedPixels2); if (pixels-&gt;r &gt;= 24 &amp;&amp; pixels-&gt;r &lt;=31 ) { numberOfRedPixels3++; } NSLog( @"Red pixel data3 %d",numberOfRedPixels3); if (pixels-&gt;r &gt;= 32 &amp;&amp; pixels-&gt;r &lt;= 39) { numberOfRedPixels4++; } NSLog( @"Red pixel data4 %d",numberOfRedPixels4); if (pixels-&gt;r &gt;= 40 &amp;&amp; pixels-&gt;r &lt;= 47) { numberOfRedPixels5++; } NSLog( @"Red pixel data5 %d",numberOfRedPixels5); if (pixels-&gt;r &gt;= 48 &amp;&amp; pixels-&gt;r &lt;= 55) { numberOfRedPixels6++; } NSLog( @"Red pixel data6 %d",numberOfRedPixels6); if(pixels-&gt;r &gt;= 56 &amp;&amp; pixels-&gt;r &lt;= 63) { numberOfRedPixels7++; } NSLog( @"Red pixel data7 %d",numberOfRedPixels7); if (pixels-&gt;r &gt;= 64 &amp;&amp; pixels-&gt;r &lt;= 71) { numberOfRedPixels8++; } NSLog( @"Red pixel data8 %d",numberOfRedPixels8); if (pixels-&gt;r &gt;= 72 &amp;&amp; pixels-&gt;r &lt;= 79) { numberOfRedPixels9++; } NSLog( @"Red pixel data9 %d",numberOfRedPixels9); if (pixels-&gt;r &gt;= 80 &amp;&amp; pixels-&gt;r &lt;= 87) { numberOfRedPixels10++; } NSLog( @"Red pixel data10 %d",numberOfRedPixels10); if (pixels-&gt;r &gt;= 88 &amp;&amp; pixels-&gt;r &lt;= 95) { numberOfRedPixels11++; } NSLog( @"Red pixel data11 %d",numberOfRedPixels11); if (pixels-&gt;r &gt;= 96 &amp;&amp; pixels-&gt;r &lt;= 103) { numberOfRedPixels12++; } NSLog( @"Red pixel data12 %d",numberOfRedPixels12); if (pixels-&gt;r &gt;= 104 &amp;&amp; pixels-&gt;r &lt;= 111) { numberOfRedPixels13++; } NSLog( @"Red pixel data13 %d",numberOfRedPixels13); if (pixels-&gt;r &gt;= 112 &amp;&amp; pixels-&gt;r &lt;= 119) { numberOfRedPixels14++; } NSLog( @"Red pixel data14 %d",numberOfRedPixels14); if (pixels-&gt;r &gt;= 120 &amp;&amp; pixels-&gt;r &lt;= 127) { numberOfRedPixels15++; } NSLog( @"Red pixel data15 %d",numberOfRedPixels15); if (pixels-&gt;r &gt; 128 &amp;&amp; pixels-&gt;r &lt;= 135) { numberOfRedPixels16++; } NSLog( @"Red pixel data16 %d",numberOfRedPixels16); if (pixels-&gt;r &gt;= 136 &amp;&amp; pixels-&gt;r &lt;= 143) { numberOfRedPixels17++; } NSLog( @"Red pixel data17 %d",numberOfRedPixels17); if (pixels-&gt;r &gt;= 144 &amp;&amp; pixels-&gt;r &lt;=151) { numberOfRedPixels18++; } NSLog( @"Red pixel data18 %d",numberOfRedPixels18); if (pixels-&gt;r &gt;= 152 &amp;&amp; pixels-&gt;r &lt;=159 ) { numberOfRedPixels19++; } NSLog( @"Red pixel data19 %d",numberOfRedPixels19); if (pixels-&gt;r &gt;= 160 &amp;&amp; pixels-&gt;r &lt;= 167) { numberOfRedPixels20++; } NSLog( @"Red pixel data20 %d",numberOfRedPixels20); if (pixels-&gt;r &gt;= 168 &amp;&amp; pixels-&gt;r &lt;= 175) { numberOfRedPixels21++; } NSLog( @"Red pixel data21 %d",numberOfRedPixels21); if (pixels-&gt;r &gt;= 176 &amp;&amp; pixels-&gt;r &lt;= 199) { numberOfRedPixels22++; } NSLog( @"Red pixel data22 %d",numberOfRedPixels22); if(pixels-&gt;r &gt;= 184 &amp;&amp; pixels-&gt;r &lt;= 191) { numberOfRedPixels23++; } NSLog( @"Red pixel data23 %d",numberOfRedPixels23); if (pixels-&gt;r &gt;= 192 &amp;&amp; pixels-&gt;r &lt;= 199) { numberOfRedPixels24++; } NSLog( @"Red pixel data24 %d",numberOfRedPixels24); if (pixels-&gt;r &gt;= 200 &amp;&amp; pixels-&gt;r &lt;= 207) { numberOfRedPixels25++; } NSLog( @"Red pixel data25 %d",numberOfRedPixels25); if (pixels-&gt;r &gt;= 208 &amp;&amp; pixels-&gt;r &lt;= 215) { numberOfRedPixels26++; } NSLog( @"Red pixel data26 %d",numberOfRedPixels26); if (pixels-&gt;r &gt;= 216 &amp;&amp; pixels-&gt;r &lt;= 223) { numberOfRedPixels27++; } NSLog( @"Red pixel data27 %d",numberOfRedPixels27); if (pixels-&gt;r &gt;= 224 &amp;&amp; pixels-&gt;r &lt;= 231) { numberOfRedPixels28++; } NSLog( @"Red pixel data28 %d",numberOfRedPixels28); if (pixels-&gt;r &gt;= 232 &amp;&amp; pixels-&gt;r &lt;= 239) { numberOfRedPixels29++; } NSLog( @"Red pixel data29 %d",numberOfRedPixels29); if (pixels-&gt;r &gt;= 240 &amp;&amp; pixels-&gt;r &lt;= 247) { numberOfRedPixels30++; } NSLog( @"Red pixel data30 %d",numberOfRedPixels30); if (pixels-&gt;r &gt;= 248) { numberOfRedPixels31++; } NSLog( @"Red pixel data31 %d",numberOfRedPixels31); pixels++; numberOfPixels--; } CGContextRelease(context); } free(pixels); } return 1; } @end My problem is I want skin Tone Pixel how it could be possible Please help me out. Thanks in Advance

    Read the article

  • iPhone: CATiledLayer/UIScrollView wont scroll after zooming and only zooms to anchor point

    - by Brodie4598
    Here is the problem... I am using CA Tiled Layer to display a large jpg. The view loads okay, and when I go to scroll around, it works fine. However, as soon as I zoom in or out once, it scrolls to the top left (to the anchor point) and will not scroll at all. The zooming works fine, but I just cannot scroll. Here is my code: #import <QuartzCore/QuartzCore.h> #import "PracticeViewController.h" @implementation practiceViewController //@synthesize image; - (void)viewDidLoad { NSString *path = [[NSBundle mainBundle] pathForResource:@"H-5" ofType:@"jpg"]; NSData *data = [NSData dataWithContentsOfFile:path]; image = [UIImage imageWithData:data]; CGRect pageRect = CGRectMake(0, 0, image.size.width, image.size.height); CATiledLayer *tiledLayer = [CATiledLayer layer]; tiledLayer.anchorPoint = CGPointMake(0.0f, 1.0f); tiledLayer.delegate = self; tiledLayer.tileSize = CGSizeMake(1000, 1000); tiledLayer.levelsOfDetail = 6; tiledLayer.levelsOfDetailBias = 0; tiledLayer.bounds = pageRect; tiledLayer.transform = CATransform3DMakeScale(1.0f, -1.0f, 0.3f); myContentView = [[UIView alloc] initWithFrame:self.view.bounds]; [myContentView.layer addSublayer:tiledLayer]; UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds]; scrollView.delegate = self; scrollView.contentSize = pageRect.size; scrollView.minimumZoomScale = .2; scrollView.maximumZoomScale = 1; [scrollView addSubview:myContentView]; [self.view addSubview:scrollView]; } - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { return myContentView; } - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx { NSString *path = [[NSBundle mainBundle] pathForResource:@"H-5" ofType:@"jpg"]; NSData *data = [NSData dataWithContentsOfFile:path]; image = [UIImage imageWithData:data]; CGRect imageRect = CGRectMake (0.0, 0.0, image.size.width, image.size.height); CGContextDrawImage (ctx, imageRect, [image CGImage]); } @end

    Read the article

  • iPhone - is it IMPOSSIBLE to grab the contents of a CALayers composition?

    - by Mike
    I have a CALayer transformed in 3D on a offscreen UIView (much larger than 320x480). How do I dump what is seen on this UIView to a UIImage? NOTE: I Have edited the question to include this code... This is how I create the layer... CGRect area = CGRectMake (0,0,400,600]; vista3D = [[UIView alloc] initWithFrame:area ]; [self.view addSubview:vista3D]; [vista3D release]; transformed = [CALayer layer]; transformed.frame = area; [vista3D.layer addSublayer:transformed]; CALayer *imageLayer = [CALayer layer]; imageLayer.doubleSided = YES; imageLayer.frame = area; imageLayer.transform = CATransform3DMakeRotation(40 * M_PI / 180.0f, 1.0f, 0.0f, 0.0f); imageLayer.contents = (id)myRawImage.CGImage; [transformed addSublayer:imageLayer]; // Add a perspective effect CATransform3D initialTransform = transformed.sublayerTransform; initialTransform.m34 = 1.0 / -500; transformed.sublayerTransform = initialTransform; // now the layer is in perspective // my next step is to "flatten" the composition into a UIImage UIImage *thisIsTheResult = some magic command thanks for any help! EDIT 1: I have tried jessecurry solution but it gives me a flat layer without any perspective. EDIT 2: I discovered a partial solution for this that works, but this solution gives me an image the size of the screen and I was looking for obtaining a higher resolution version, rendering off screen.

    Read the article

  • Creating a UIImage from a rotated UIImageView...

    - by Magic Bullet Dave
    I have a UIImageView with an image in it. I have rotated the image prior to display by setting the transform property of the UIImageView to CGAffineTransformMakeRotation(angle) where angle is the angle in radians. I want to be able to create another UIImage that corresponds to the rotated version that I can see in my view. I am almost there, by rotating the image context I get a rotated image: - (UIImage *) rotatedImageFromImageView: (UIImageView *) imageView { UIImage *rotatedImage; // Get image width, height of the bonuding rectangle CGRect boundingRect = [self getBoundingRectAfterRotation: imageView.bounds byAngle:angle]; // Create a graphics context the size of the boundinf rectangle UIGraphicsBeginImageContext(boundingRect.size); CGContextRef context = UIGraphicsGetCurrentContext(); // Rotate and translate the context CGAffineTransform ourTransform = CGAffineTransformIdentity; ourTransform = CGAffineTransformConcat(ourTransform, CGAffineTransformMakeRotation(angle)); CGContextConcatCTM(context, ourTransform); // Draw the image into the context CGContextDrawImage(context, CGRectMake(0, 0, imageView.image.size.width, imageView.image.size.height), imageView.image.CGImage); // Get an image from the context rotatedImage = [UIImage imageWithCGImage: CGBitmapContextCreateImage(context)]; // Clean up UIGraphicsEndImageContext(); return rotatedImage; } However the image is not rotated about its centre. I have tried all kinds of transforms concatenated with my rotate to get it to rotate around the centre but to no avail. Am I missing a trick? Is this even possible since I am rotating the context not the image? Getting desperate to make this work now, so any help would be appreciated. Dave

    Read the article

  • UIImage Shadow Trouble

    - by Brandon Schlenker
    I'm trying to add a small shadow to an image, much like the icon shadows in the App Store. Right now I'm using the following code to round the corners of my images. Does anyone know how I can adapt it to add a small shadow? - (UIImage *)roundCornersOfImage:(UIImage *)source height:(int)height width:(int)width { int w = width; int h = height; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef imageContext = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst); CGContextBeginPath(imageContext); CGRect rect = CGRectMake(0, 0, w, h); addRoundedRectToPath(imageContext, rect, 10, 10); CGContextClosePath(imageContext); CGContextClip(imageContext); CGContextDrawImage(imageContext, CGRectMake(0, 0, w, h), source.CGImage); CGImageRef imageMasked = CGBitmapContextCreateImage(imageContext); CGContextRelease(imageContext); CGColorSpaceRelease(colorSpace); return [UIImage imageWithCGImage:imageMasked]; } "addRoundedRectToPath" refers to another method that obviously rounds the corners.

    Read the article

  • Problem in cropping the UIImage using CGContext?

    - by Rajendra Bhole
    Hi, I developing the simple UIApplication in which i want to crop the UIImage (in .jpg format) with help of CGContext. The developed code till now as follows, CGImageRef graphicOriginalImage = [originalImage.image CGImage]; UIGraphicsBeginImageContext(originalImage.image.size); CGContextRef ctx = UIGraphicsGetCurrentContext(); CGBitmapContextCreateImage(graphicOriginalImage); CGFloat fltW = originalImage.image.size.width; CGFloat fltH = originalImage.image.size.height; CGFloat X = round(fltW/4); CGFloat Y =round(fltH/4); CGFloat width = round(X + (fltW/2)); CGFloat height = round(Y + (fltH/2)); CGContextTranslateCTM(ctx, 0, image.size.height); CGContextScaleCTM(ctx, 1.0, -1.0); CGRect rect = CGRectMake(X,Y ,width ,height); CGContextDrawImage(ctx, rect, graphicOriginalImage); croppedImage = UIGraphicsGetImageFromCurrentImageContext(); return croppedImage; } The above code is worked fine but it can't crop image. The original image memory and cropped image memory i will got same(equal to original image memory). The above code is right for cropping the image?????????????????? How i cropping the image (in behind pixels should also be crop) from the center of the image???????????? I already wasting a lot of time for developing the above code , but i didn't get answer or way to find out how to crop the image.Thanks for sending me answer in advanced.

    Read the article

  • How to Anti-Alias Layers in iPhoneOS

    - by Shannon A.
    We've had Reiner Knizia's Money out for a couple of months now. It's done pretty well, and so we've been updating it as time allows. However, one thing continues to bug me. I've never been able to get my layered cards to anti-alias correctly. Here's a sample: Cards that are laid straight are very clean, but whenever they're angled the black lines around the cards get jagged. I've tried this depending on both lines implicit to the artwork and lines drawn through drawRect:, and they both do the same thing. I've tried the edgeAntiAliasingMask and it doesn't do a thing as far as I can tell. I've tried masksToBounds for the sublayers set to NO and YES. Right now my card is set up as a CALayer that has sub-CALayers for the front and the back, plus for a few other things like a lightening mask and a darkening mask. Here's some snippets of the code: CArdLayer *theCardLayer = [CArdLayer layer]; theCardLayer.edgeAntialiasingMask = kCALayerLeftEdge | kCALayerRightEdge | kCALayerBottomEdge | kCALayerTopEdge; theCardLayer.front = [CALayer layer]; theCardLayer.front.edgeAntialiasingMask = kCALayerLeftEdge | kCALayerRightEdge | kCALayerBottomEdge | kCALayerTopEdge; theCardLayer.front.bounds = theCardLayer.bounds; theCardLayer.front.masksToBounds = YES; theCardLayer.front.contents = (id)[cardDrawing CGImage]; [theCardLayer addSublayer:theCardLayer.front]; Etc ... Any ideas on how to make the cards actually anti-alias?

    Read the article

  • UIImage resize (Scale proportion)

    - by Mustafa
    The following piece of code is resizing the image perfectly, but the problem is that it messes up the aspect ratio (resulting in a skewed image). Any pointers? // Change image resolution (auto-resize to fit) + (UIImage *)scaleImage:(UIImage*)image toResolution:(int)resolution { CGImageRef imgRef = [image CGImage]; CGFloat width = CGImageGetWidth(imgRef); CGFloat height = CGImageGetHeight(imgRef); CGRect bounds = CGRectMake(0, 0, width, height); //if already at the minimum resolution, return the orginal image, otherwise scale if (width <= resolution && height <= resolution) { return image; } else { CGFloat ratio = width/height; if (ratio > 1) { bounds.size.width = resolution; bounds.size.height = bounds.size.width / ratio; } else { bounds.size.height = resolution; bounds.size.width = bounds.size.height * ratio; } } UIGraphicsBeginImageContext(bounds.size); [image drawInRect:CGRectMake(0.0, 0.0, bounds.size.width, bounds.size.height)]; UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return imageCopy; }

    Read the article

  • trying to draw scaled UIImage in custom view, but nothing's rendering

    - by Ben Collins
    I've created a custom view class and right now just want to draw an image scaled to fit the view, given a UIImage. I tried just drawing the UIImage.CGImage, but as others have attested to on this site (and in the docs), that renders the image upside down. So, at the suggestion of an answer I found to another question, I'm trying to draw it directly, but nothing is rendering in the view and I'm not sure why. Here's my drawing code: - (void)drawRect:(CGRect)rect { // Drawing code [super drawRect:rect]; if (self.originalImage) { [self drawImage]; } } - (void) drawImage { if (CGSizeEqualToSize(originalImage.size, self.frame.size) == NO) { CGFloat scaleFactor = 1.0; CGFloat scaledWidth = 0.0; CGFloat scaledHeight = 0.0; CGPoint thumbPoint = CGPointMake(0.0, 0.0); CGFloat widthFactor = self.frame.size.width / originalImage.size.width; CGFloat heightFactor = self.frame.size.height / originalImage.size.height; if (widthFactor < heightFactor) { scaleFactor = widthFactor; } else { scaleFactor = heightFactor; } scaledWidth = originalImage.size.width * scaleFactor; scaledHeight = originalImage.size.height * scaleFactor; if (widthFactor < heightFactor) { thumbPoint.y = (self.frame.size.height - scaledHeight) * 0.5; } else if (widthFactor > heightFactor) { thumbPoint.x = (self.frame.size.width - scaledWidth) * 0.5; } UIGraphicsBeginImageContext(self.frame.size); CGRect thumbRect = CGRectZero; thumbRect.origin = thumbPoint; thumbRect.size.width = scaledWidth; thumbRect.size.height = scaledHeight; [originalImage drawInRect:thumbRect]; self.scaledImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); } else { self.scaledImage = originalImage; } } My understanding (after studying this a bit) is that the UIGraphicsBeginImageContext function creates an offscreen for me to draw into, so now how do I render that context on top of the original one?

    Read the article

  • CAScrollLayer doesn't scroll!

    - by Cliff
    Maybe it's because it's late. Whatever the reason I can't figure out why I'm having trouble with a simple CSScrollLayer example I'm trying. I add a 50 pixel Eclipse icon to a view based project and in my initialize method (called from initWithNibName:bundle:) I have this: -(void) initialize { CAScrollLayer *scrollLayer = [CAScrollLayer layer]; scrollLayer.backgroundColor = [[UIColor blackColor] CGColor]; CGRect bounds = self.view.bounds; scrollLayer.bounds = CGRectMake(0, 0, bounds.size.width, bounds.size.height); scrollLayer.contentsRect = CGRectMake(0, 0, bounds.size.width + 800, bounds.size.height + 800); scrollLayer.borderWidth = 2.5; scrollLayer.borderColor = [[UIColor redColor] CGColor]; scrollLayer.position = CGPointMake(self.view.center.x, self.view.center.y - 20); scrollLayer.scrollMode = kCAScrollBoth; [self.view.layer addSublayer:scrollLayer]; UIImage *image = [UIImage imageNamed:@"eclipse32.gif"]; for(int i=0; i<6; i++) { layer = [CALayer layer]; layer.backgroundColor = [[UIColor blackColor] CGColor]; layer.bounds = CGRectMake(0, 0, 100, 100); layer.contents = (id)[image CGImage]; layer.position = CGPointMake(layer.bounds.size.width * i, self.view.center.y); [scrollLayer addSublayer:layer]; } // [button removeFromSuperview]; // [self.view addSubview:button]; // self.view.userInteractionEnabled = YES; [image release]; } The scroll layer shows, the icon is repeated on the layer I have a border around the edge of the screen. Everything is lovely except I can't scroll the icons. I've tried with/without setting scroll mode. I've tried with a single stretched icon that falls off screen. I've tried everything. What am I doing wrong?

    Read the article

  • iPhone OS: Strategies for high density image work

    - by Jasconius
    I have a project that is coming around the bend this summer that is going to involve, potentially, an extremely high volume of image data for display. We are talking hundreds of 640x480-ish images in a given application session (scaled to a smaller resolution when displayed), and handfuls of very large (1280x1024 or higher) images at a time. I've already done some preliminary work and I've found that the typical 640x480ish image is just a shade under 1MB in memory when placed into a UIImageView and displayed... but the very large images can be a whopping 5+ MB's in some cases. This project is actually be targeted at the iPad, which, in my Instruments tests seems to cap out at about 80-100MB's of addressable physical memory. Details aside, I need to start thinking of how to move huge volumes of image data between virtual and physical memory while preserving the fluidity and responsiveness of the application, which will be high visibility. I'm probably on the higher ends of intermediate at Objective-C... so I am looking for some solid articles and advice on the following: 1) Responsible management of UIImage and UIImageView in the name of conserving physical RAM 2) Merits of using CGImage over UIImage, particularly for the huge images, and if there will be any performance gain 3) Anything dealing with memory paging particularly as it pertains to images I will epilogue by saying that the numbers I have above maybe off by about 10 or 15%. Images may or may not end up being bundled into the actual app itself as opposed to being loaded in from an external server.

    Read the article

  • Why won't my CATiledLayer scroll in a UIScrollView after zooming?

    - by Brodie4598
    I'm currently having the following problem with CATiledLayer: when the view first loads, the scrolling works perfectly, but then when you zoom once, the view snaps to the anchor point (top left corner) and it can no longer scroll at all. The zooming works in that it will zoom in and out, but it will only zoom to the top left corner. My code is as follows: #import <QuartzCore/QuartzCore.h> #import "PracticeViewController.h" @implementation practiceViewController //@synthesize image; - (void)viewDidLoad { NSString *path = [[NSBundle mainBundle] pathForResource:@"H-5" ofType:@"jpg"]; NSData *data = [NSData dataWithContentsOfFile:path]; image = [UIImage imageWithData:data]; CGRect pageRect = CGRectMake(0, 0, image.size.width, image.size.height); CATiledLayer *tiledLayer = [CATiledLayer layer]; tiledLayer.anchorPoint = CGPointMake(0.0f, 1.0f); tiledLayer.delegate = self; tiledLayer.tileSize = CGSizeMake(1000, 1000); tiledLayer.levelsOfDetail = 6; tiledLayer.levelsOfDetailBias = 0; tiledLayer.bounds = pageRect; tiledLayer.transform = CATransform3DMakeScale(1.0f, -1.0f, 0.3f); myContentView = [[UIView alloc] initWithFrame:self.view.bounds]; [myContentView.layer addSublayer:tiledLayer]; UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds]; scrollView.delegate = self; scrollView.contentSize = pageRect.size; scrollView.minimumZoomScale = .2; scrollView.maximumZoomScale = 1; [scrollView addSubview:myContentView]; [self.view addSubview:scrollView]; } - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { return myContentView; } - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx { NSString *path = [[NSBundle mainBundle] pathForResource:@"H-5" ofType:@"jpg"]; NSData *data = [NSData dataWithContentsOfFile:path]; image = [UIImage imageWithData:data]; CGRect imageRect = CGRectMake (0.0, 0.0, image.size.width, image.size.height); CGContextDrawImage (ctx, imageRect, [image CGImage]); } @end

    Read the article

  • How to move/drag multiple images with CALayer???

    - by gbf.sara
    I have more than 10 images in screen and i want to move each image using CALayer concept. While am trying to move first image,its working. Even when i drag my second image also, its working. But after that when i get back to first image and when i try to move , am struck up. its not working. I dono where it went wrong. Here's ma code //Assigning Layer to UIImage// layer = [CALayer layer]; UIImage *image1 = [UIImage imageNamed:[NSString stringWithFormat:@"%@_thumb.png",[tiv imageName]]]; layer.contents = (id)image1.CGImage; layer.position=CGPointMake(200,200); layer.frame = CGRectMake(110, 180, 100, 100); [self.view.layer addSublayer:layer]; [layer needsDisplay]; [self.view.layer needsDisplay]; [layer needsLayout]; //Here i try to move my image// - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesMoved:touches withEvent:event]; NSArray *allTouches = [touches allObjects]; int count = [allTouches count]; if (count == 1) { if (CGRectContainsPoint([layer frame], [[allTouches objectAtIndex:0] locationInView:self.view])) { layer.position = [[allTouches objectAtIndex:0] locationInView:self.view]; return; } } if (count > 1) { if (CGRectContainsPoint([layer frame], [[allTouches objectAtIndex:-1] locationInView:self.view])) { layer.position = [[allTouches objectAtIndex:0] locationInView:self.view]; return; } } } Also ive planned to use single CALayer for multiple images.. When i click an image, it should be placed in that CALayer and when i click another, the same CALayer should take the latter one. So tat whenever i drag an image it should move(no matter how many images r there) . Do u think this concept will work out or is there any other idea??? My concept may seems to be a basic one. Am new to this environment n so kindly help me..

    Read the article

  • Trouble when changing pixel data with alpha on png on iphone --okay on simulator

    - by Ted
    I'm trying to change the color of the pixels (lighten or darken) without changing the value of the alpha channel using CGDataProviderCopyData. I leave every 4th databyte untouched. It work fine of the iphone simulator, however on the real thing the alpha goes white as I increase the values of the other pixels. I've tried changing just the first byte, or the second, or the third. Does anybody have any idea what is going on? The basic code is borrowed from Jorge. I like this simple approach --I'm new to this. But I want to make it work with png images with some transparency. here is most of the code by Jorge : CFDataRef CopyImagePixels(CGImageRef inImage){ return CGDataProviderCopyData(CGImageGetDataProvider(inImage)); } CGImageRef img=originalImage.CGImage; CFDataRef dataref=CopyImagePixels(img); UInt8 *data=(UInt8 *)CFDataGetBytePtr(dataref); int length=CFDataGetLength(dataref); for(int index=0;index255){ data[index+i]=255; }else{ data[index+i]+=value; } } } } size_t width=CGImageGetWidth(img); size_t height=CGImageGetHeight(img); size_t bitsPerComponent=CGImageGetBitsPerComponent(img); size_t bitsPerPixel=CGImageGetBitsPerPixel(img); size_t bytesPerRow=CGImageGetBytesPerRow(img); CGColorSpaceRef colorspace=CGImageGetColorSpace(img); CGBitmapInfo bitmapInfo=CGImageGetBitmapInfo(img); CGImageAlphaInfo alphaInfo = kCGBitmapAlphaInfoMask(img); NSLog(@"bitmapinfo: %d",bitmapInfo); CFDataRef newData=CFDataCreate(NULL,data,length); CGDataProviderRef provider=CGDataProviderCreateWithCFData(newData); CGImageRef newImg=CGImageCreate(width,height,bitsPerComponent,bitsPerPixel,bytesPerRow,colorspace,bitmapInfo,provider,NULL,true,kCGRenderingIntentDefault); [iv setImage:[UIImage imageWithCGImage:newImg]]; CGImageRelease(newImg); CGDataProviderRelease(provider);

    Read the article

< Previous Page | 1 2 3 4 5  | Next Page >