Creating Thumbnails in Build Phase of iPhone App Xcode project?
I have a group of png files in my bundle; but I also want smaller versions of them to be used at my app a开发者_如何学Gos well. Right now I am just resizing them all manually and putting them in the bundle as well: so i might have Graphic_1.png and Graphic_1-thumbnail.png.
Instead, is there anyway to do something like: at build time, take all my png assets and create 1/4 scale versions of them, and save them into the bundle as well, with the -thumbnail in the filename as above? Thanks!
You can create a bash script for a custom build phase of your project. (Haven't tried to see if automator would work) This would require you to have something like Image Magick installed.
Right click on your target and click "Add > New Build Phase > New Run Script Build Phase"
Set the shell to /bin/bash. For the script:
FILES="*.png"
for f in "$FILES"
do
`convert $f -resize 25% thumb-$f`
done
Any other command line image processing tool would work in place of Image Magick. You likely need to adjust the FILES variable to the real location of your images.
U try this
- (UIImage*)resizingImagewithimagename:(UIImage *)inImage Length:(CGFloat)length
{
UIGraphicsBeginImageContext(CGSizeMake(length,length));
[inImage drawInRect: CGRectMake(0, 0, length, length)];
UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return smallImage;
}
精彩评论