Right now I have a class that downloads data from a URL and store it in a variable named "data".
I have been using UIImage and UIImageView to display the data. Problem is, everytime I need to crop a region of it, I am running into some serious issues.
1) You can crop parts of the UIImage using CGImageCreateWithImageInRect, yet it is completely unproportional when viewed in UIImageView. I am not sure if it is UIImageView or UIImage's fault, but there appears to be a number of annoying responses on google that supposedly solve this issue, and yet they don't. One even extends the category of UIImage, which I feel is a little ridiculous and uncalled for.
Are there better ways of handling image data? If so, what is a very clean, efficient, and usable way to take data, display it, and then when I want to crop a part of its region to update the display with the new clip using the same object? In other words, the same UIImageView so that I don't have to recreate one every time.
Here's my code so far, which isn't working correctly. It sort of works, but then the cropped region is clipped seemingly to the previous proportions of the image. Thus, I am not getting a 32x32 image. I am getting a 32xwhatever image, height being clipped to match the previous aspect ratio.
I have been using UIImage and UIImageView to display the data. Problem is, everytime I need to crop a region of it, I am running into some serious issues.
1) You can crop parts of the UIImage using CGImageCreateWithImageInRect, yet it is completely unproportional when viewed in UIImageView. I am not sure if it is UIImageView or UIImage's fault, but there appears to be a number of annoying responses on google that supposedly solve this issue, and yet they don't. One even extends the category of UIImage, which I feel is a little ridiculous and uncalled for.
Are there better ways of handling image data? If so, what is a very clean, efficient, and usable way to take data, display it, and then when I want to crop a part of its region to update the display with the new clip using the same object? In other words, the same UIImageView so that I don't have to recreate one every time.
Here's my code so far, which isn't working correctly. It sort of works, but then the cropped region is clipped seemingly to the previous proportions of the image. Thus, I am not getting a 32x32 image. I am getting a 32xwhatever image, height being clipped to match the previous aspect ratio.
Code:
- ( void )process
{
UIImage* bitmap = [ [ UIImage alloc ] initWithData:data ];
image = [ [ UIImageView alloc ] initWithImage:bitmap ];
[ bitmap release ];
[ self addSubview:image ];
CGRect rect = CGRectMake( 0, 0, 32, 32 );
[ self setImagePart:rect ];
};
- ( void )setImagePart:( CGRect )prect
{
UIImage* bitmap = [ [ UIImage alloc ] initWithData:data ];
CGImageRef crop = CGImageCreateWithImageInRect( [ bitmap CGImage ], prect );
[ image setImage:[ UIImage imageWithCGImage:crop ] ];
CGImageRelease( crop );
image.frame = prect;
[ bitmap release ];
}