Objective c 带NSData但不带大小的UIImage
我有以下代码:Objective c 带NSData但不带大小的UIImage,objective-c,uiimage,size,nsdata,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]; ... 我需要调
...
NSData * dimage = [[NSData alloc]initWithData:[datosImagen objectForKey:@"Image"]];
UIImage * imagenAMostrar = [[UIImage alloc] initWithData:dimage];
UIImageView * imAMostrar = [[UIImageView alloc] initWithImage:imagenAMostrar];
...
我需要调整UIImageView的大小,类似于以下尺寸:setFrame:CGRectMake(0,60320240)
。
但为此,我需要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
为什么?您应该得到一个转换类型警告<代码>宽度和高度是
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);
您可以这样设置图像视图的框架
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);
您在NSLog语句中没有收到任何警告吗?您应该得到一个转换类型警告<代码>宽度和高度是
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);
您可以这样设置图像视图的框架
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);
如果([UIImage imageWithData:dimage])不忽略警告,它们会帮助您。您可以先检查图像对象是否创建,如果([UIImage imageWithData:dimage])不忽略警告,它们会帮助您。