FORUM CLOSED, PLEASE REGISTER AT FORUM.SIO2INTERACTIVE.COM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Manipulating RAW pixels from UIImage

2 posters

Go down

Manipulating RAW pixels from UIImage Empty Manipulating RAW pixels from UIImage

Post  afastrunner 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

Back to top Go down

Manipulating RAW pixels from UIImage Empty Re: Manipulating RAW pixels from UIImage

Post  sio2interactive 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;
}

sio2interactive
sio2interactive

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

http://sio2interactive.com

Back to top Go down

Manipulating RAW pixels from UIImage Empty Re: Manipulating RAW pixels from UIImage

Post  afastrunner 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

Back to top Go down

Manipulating RAW pixels from UIImage Empty Re: Manipulating RAW pixels from UIImage

Post  sio2interactive 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
sio2interactive
sio2interactive

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

http://sio2interactive.com

Back to top Go down

Manipulating RAW pixels from UIImage Empty Re: Manipulating RAW pixels from UIImage

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

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