没有大小的NSData的UIImage

时间:2011-10-03 11:33:22

标签: objective-c uiimage size nsdata

我有这段代码:

...
NSData * dimage = [[NSData alloc]initWithData:[datosImagen objectForKey:@"Image"]];
UIImage * imagenAMostrar = [[UIImage alloc] initWithData:dimage];
UIImageView * imAMostrar = [[UIImageView alloc] initWithImage:imagenAMostrar];
...

我需要调整我的UIImageView大小,类似于这个尺寸:setFrame:CGRectMake(0,60,320,240)。 但为此我需要UIImageView大小......

NSLog(@" Image width:%d",imagenAMostrar.size.width);
NSLog(@" Image height:%d",imagenAMostrar.size.height);

结果是:

2011-10-03 13:32:28.993 Catalogo-V1[2679:207] Image width:0
2011-10-03 13:32:28.994 Catalogo-V1[2679:207] Image height:0

为什么?

1 个答案:

答案 0 :(得分:1)

您是否在 NSLog 语句中收到任何警告?您应该收到转换类型警告。 width height float-s 。您应该使用%f作为转换说明符。你应该像这样打印它们,

NSLog(@" Image width:%f", imagenAMostrar.size.width);
NSLog(@" Image height:%f", imagenAMostrar.size.height);

您可以像这样设置图像视图的框架

imAMostrar.frame = CGRectMake(0, 60, imagenAMostrar.size.width, imagenAMostrar.size.height);