开发者

iPhone - turn resized image into full screen bitmap

I have images with many different ratios that are being resized (downscaled) to iPhone/iPad screen size.

What I need to achieve is to create full screen bitmaps (960x640, 480x320, 1024x768) with this image centered & resized and including the black border. Scaling is done automatically by AspectFit but how do I turn the result to fullscreen image?

On Android I'm using imageview.buildDrawingCache(); and imageview.getDrawingCache();. Not the fastest solution but is good enough for me.

For example:

  • Image size: 1000x500
  • Image scaled on iPhone4 to: 960x480
  • iPhone开发者_StackOverflow4 resolution & the image size I need: 960x640

Any idea how to solve this problem?

I will need this image in memory for like 2 minutes and then I can clean it.

EDIT: This is what I need - change bitmap scaled into bitmap scaled WITH the surrounding.

iPhone - turn resized image into full screen bitmap


You can resize you image using imagecontext

UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"stack" ofType:@"png"]];

UIGraphicsBeginImageContext(image.size); 
[image1 drawInRect:CGRectMake(0, 0, 960, 480)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext();

i think this will help..!!


I'm not sure what your problem is. If you need help on how to resize an image, check this tutorial: Resize a UIImage the right way

If you want to present a retina image on a iPhone 4, you can use this code:

UIImage *image = [UIImage imageNamed:@"scaledPicture.png"];
CGRect imageframe = CGRectMake(0,0,imageWidth/2,imageHeight/2);
UIImageView *imageview = [[UIImageView] initWithFrame:imageframe];
[window addSubView:imageview]; 

The numbers you write in CGRect are points, not pixels. On iPhone 4, 1 point = 2 pixels. Thats why the actual width and height are divided by 2 in the above code.

Hope this helps....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜