Manipulating RAW pixels from UIImage

View previous topic View next topic Go down

Manipulating RAW pixels from UIImage

Post  afastrunner on Wed Feb 11, 2009 3:39 pm

Can anyone here help me get the raw (as in bitmap data array) from an UIImage (in my case returned from imagepicker)

I'm seen several apps that do image processing so i know it's possible. The posts/articles that google has given me have been filled with things like "well I think it's like in OSX and you can do X" but haven't seen any code that seems to work for me.

Thanks a million in advance Smile

afastrunner

Posts : 4
Join date : 2009-01-25

View user profile

Back to top Go down

Re: Manipulating RAW pixels from UIImage

Post  sio2interactive on Wed Feb 11, 2009 4:03 pm

Code:


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
   SIO2image *_SIO2image = NULL;
   
   CGImageRef img;
   CGContextRef ctx;

   // Create a new image
   _SIO2image = sio2ImageInit( "image/wall.tga" );
   
   img = image.CGImage;
   

   // Take the image selected inside the image picker controller
   // and create a texture from it.
   if( img )
   {
      HAVEPIC = 1;
      
      _SIO2image->width  = CGImageGetWidth( img );
      _SIO2image->height = CGImageGetHeight( img );   
      _SIO2image->bits  = 4;
      
      _SIO2image->tex = ( unsigned char *) malloc( _SIO2image->width  *
                                        _SIO2image->height *
                                        _SIO2image->bits );
      
      ctx = CGBitmapContextCreate( _SIO2image->tex,
                            _SIO2image->width,
                            _SIO2image->height,
                            8,
                            _SIO2image->width * _SIO2image->bits,
                            CGImageGetColorSpace( img ),
                            kCGImageAlphaPremultipliedLast );
      
      CGContextDrawImage( ctx,
                     CGRectMake( 0.0, 0.0,
                              (CGFloat)_SIO2image->width,
                              (CGFloat)_SIO2image->height ), img );
      
      CGContextRelease( ctx );
   
      // Scale the image to the nearest power of 2
      sio2ImageScale( _SIO2image,
                  sio2GetNextPow2( _SIO2image->width ),
                  sio2GetNextPow2( _SIO2image->height ) );
   
      // Convert RGBA to BGRA since SIO2 only support
      // BGRA for 32bits texture.
      sio2ImageRGBAtoBGRA( _SIO2image );
   
      // Generate the texture ID
      sio2ImageGenId( _SIO2image, SIO2_IMAGE_CLAMP, 0.0f );
   }
   
   // Hide our image picker.
    imagePickerController.view.hidden = YES;
}

avatar
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 38
Location : Shanghai

View user profile http://sio2interactive.com

Back to top Go down

Re: Manipulating RAW pixels from UIImage

Post  afastrunner on Wed Feb 11, 2009 4:15 pm

At what point though would I be able to modify the pixels to change to greyscale or perform an edge detect filter etc?

afastrunner

Posts : 4
Join date : 2009-01-25

View user profile

Back to top Go down

Re: Manipulating RAW pixels from UIImage

Post  sio2interactive on Wed Feb 11, 2009 4:20 pm

Before sio2ImageGenId, all the pixels are ordered properly in _SIO2image->tex (BGRA), or if you want to work with RGBA before sio2ImageRGBAtoBGRA Wink
avatar
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 38
Location : Shanghai

View user profile http://sio2interactive.com

Back to top Go down

Re: Manipulating RAW pixels from UIImage

Post  Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum