Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-18-2009, 06:14 PM   #26 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 14
Default

Quote:
Originally Posted by PhoneyDeveloper View Post
Code:
//	resizedImage
...
Phoney, there are some problems with your code. In particular, the last parameter takes a CGBitmapInfo type, but you're passing a CGImageAlphaInfo type. This can chop off the byte ordering information stored in CGBitmapInfo, resulting in odd problems such as pink-tinted images. Also, you're hard coding the bytesPerRow value when in fact it should be based on the original image. The following is a revised version of your code:

Code:
// Returns a rescaled copy of the image; its imageOrientation will be UIImageOrientationUp
// If the new size is not integral, it will be rounded up
- (UIImage *)makeResizedImage:(CGSize)newSize quality:(CGInterpolationQuality)interpolationQuality {
    CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height));
    CGImageRef imageRef = self.CGImage;

    // Compute the bytes per row of the new image
    size_t bytesPerRow = CGImageGetBitsPerPixel(imageRef) / CGImageGetBitsPerComponent(imageRef) * newRect.size.width;
    bytesPerRow = (bytesPerRow + 15) & ~15;  // Make it 16-byte aligned
    
    // Build a bitmap context that's the same dimensions as the new size
    CGContextRef bitmap = CGBitmapContextCreate(NULL,
                                                newRect.size.width,
                                                newRect.size.height,
                                                CGImageGetBitsPerComponent(imageRef),
                                                bytesPerRow,
                                                CGImageGetColorSpace(imageRef),
                                                CGImageGetBitmapInfo(imageRef));
    
    CGContextSetInterpolationQuality(bitmap, interpolationQuality);

    // Draw into the context; this scales the image
    CGContextDrawImage(bitmap, newRect, imageRef);
    
    // Get the resized image from the context and a UIImage
    CGImageRef resizedImageRef = CGBitmapContextCreateImage(bitmap);
    UIImage *resizedImage = [UIImage imageWithCGImage:resizedImageRef];
    
    // Clean up
    CGContextRelease(bitmap);
    CGImageRelease(resizedImageRef);
    
    return resizedImage;
}
As with your original function, this code works as expected only when UIImage.imageOrientation == UIImageOrientationUp.

Last edited by vocaro; 08-19-2009 at 03:11 PM.
vocaro is offline   Reply With Quote
Old 09-01-2009, 02:01 PM   #27 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 153
Default

Hi,
Boy, this is such a newbie question, but I need to use Phoney's code for shrinking an image, and I can't figure out how to call the function:

UIImage *imgMyShrunkenImage = ?????

In my code, I turned phoney's
UIImage* resizedImage(UIImage *inImage, CGRect thumbRect)

into:
-(UIImage*)resizedImage:(UIImage*)inImage inRect:(CGRect)thumbRect {

because I'm more familiar with that syntax, but I need to know how to complete the line that calls the funtion or method, passing an image and a rect, and creating a UIImage that I can then use.

Thanks for any help.
/Steve
StevenD is offline   Reply With Quote
Old 09-02-2009, 02:47 AM   #28 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 14
Default

I'm not sure how one can be familiar with the syntax of a declaration and yet be unfamiliar with its invocation, but anyway... Have you considered:

Code:
UIImage *imgMyShrunkenImage = [self resizedImage:img inRect:rect];
vocaro is offline   Reply With Quote
Old 09-02-2009, 10:05 AM   #29 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 153
Default

Thanks, vocaro,

Sorry. Total brain f**t. I guess I was so excited to find this post, phoney's code, and also especially the code you referred us to, which takes image orientation into account. *Incredibly* useful for the app I'm working on. Lifesaver. Thanks.

/Steve
StevenD is offline   Reply With Quote
Old 10-05-2009, 02:36 PM   #30 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 5
Default What was your tweak?

Quote:
Originally Posted by shawn View Post
Thanks Phoney! With a few tweaks that method worked great with no warnings!
Hi Shawn, what was your tweak to the PhonyDeveloper's code?

Is that something similar to vocaro's code on page 2 of this thread?

Thanks,
Yoichi
yoichi is offline   Reply With Quote
Old 12-10-2009, 05:24 AM   #31 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 1
Default

Quote:
I made two method for reszing.
#2 incorrectly resize some images in _sumlator_
maintainer is offline   Reply With Quote
Old 01-14-2011, 11:42 PM   #32 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 1
Default how to resize an image

if you want to resize image than i will you suggest you to visit the below link
Learn & Share your experience! • View topic - Resizing image using asp.net-2.0(vb)
please visit the link, here you can know about how to resize image.
thank you very much.
inzamam is offline   Reply With Quote
Old 01-15-2011, 12:58 AM   #33 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 4,999
Default

How on Earth is ASP/VB .Net related to anything here?
baja_yu is offline   Reply With Quote
Old 09-13-2011, 02:55 AM   #34 (permalink)
Registered Member
 
Join Date: Aug 2011
Location: Ahmedabad
Posts: 4
Default

Quote:

// There's a wierdness with kCGImageAlphaNone and CGBitmapContextCreate
// see Supported Pixel Formats in the Quartz 2D Programming Guide
// Creating a Bitmap Graphics Context section
// only RGB 8 bit images with alpha of kCGImageAlphaNoneSkipFirst, kCGImageAlphaNoneSkipLast, kCGImageAlphaPremultipliedFirst,
// and kCGImageAlphaPremultipliedLast, with a few other oddball image kinds are supported
// The images on input here are likely to be png or jpeg files
How to get rid of this ??
DimplePanchal is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 255
15 members and 240 guests
@sandris, ADY, Alsahir, dacapo, Dani77, Desert Diva, djohnson, HemiMG, jansan, M@realobjects, MarkC, prchn4christ, smethorst, tomtom100
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,882
Threads: 89,228
Posts: 380,762
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jansan
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:57 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0