ALAsset 缩略图清晰度较低
我使用 ALAsset Library 将照片库图像绑定到我的表格视图。 因此,每当我将 ALAsset 缩略图图像绑定为 TableView 单元格图像时,图像清晰度就会出现问题。它显示为低清晰度图像。 我已经从 AlAsset 创建了全分辨率图像并编写了缩略图生成方法,我已将生成的图像设置为表格视图图像。 完成上述过程后,我在表格视图上获得了全分辨率图像缩略图。 但问题是第一次表视图图像绑定过程的性能(我在第一次绑定后使用缓存来绑定图像。所以第一次后性能会很快)。
所以我可以知道,如何从 ALAsset 获取照片库全清晰度缩略图?
我在 MyTableView CellForRowIndexPath 中编写了以下代码,
UIImageView *importMediaSaveImage=[[[UIImageView alloc] init] autorelease];
importMediaSaveImage.frame=CGRectMake(0, 0, 200,135 );
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
CGImageRef iref = [myasset thumbnail];
if (iref) {
importMediaSaveImage.image = [UIImage imageWithCGImage:iref];
}
etc...
我尝试了以下方法,该方法非常耗时
UIImageView *importMediaSaveImage=[[[UIImageView alloc] init] autorelease];
importMediaSaveImage.frame=CGRectMake(0, 0, 200,135 );
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
UIImage *images;
if (iref) {
images = [UIImage imageWithCGImage:iref];
}
NSData *data = [self photolibImageThumbNailData:images];
importMediaSaveImage.image = [UIImage imageWithData:data];
etc....
photolibImageThumbNailData
-(NSData *)photolibImageThumbNailData:(UIImage *)image{
// begin an image context that will essentially "hold" our new image
UIGraphicsBeginImageContext(CGSizeMake(200.0,135.0));
// now redraw our image in a smaller rectangle.
[image drawInRect:CGRectMake(0.0, 0.0, 200.0, 135.0)];
// make a "copy" of the image from the current context
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// now grab the PNG representation of our image
NSData *thumbData = UIImagePNGRepresentation(newImage);
return thumbData;
}
谢谢。
I am binding the photo Library images to my Table-view using ALAsset Library.
So whenever i am binding the ALAsset Thumbnail image as a TableView cell image, there is a issue with image Clarity.It Shows as a low clarity image.
I have Created a full resolution image from AlAsset and wrote the thumbnail generation method, i have set the resultant image as table-view image.
After done the above process, i got the full resolution image thumbnail on Table-view.
But the issue was the performance with first time table View image bind process(i used a cache to bind the image after bind first time.So the performance will fast after first time).
So May i know, How can i get the Photo-library full clarity thumbnail image from ALAsset?
I have wrote the below code in MyTableView CellForRowIndexPath is
UIImageView *importMediaSaveImage=[[[UIImageView alloc] init] autorelease];
importMediaSaveImage.frame=CGRectMake(0, 0, 200,135 );
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
CGImageRef iref = [myasset thumbnail];
if (iref) {
importMediaSaveImage.image = [UIImage imageWithCGImage:iref];
}
etc...
I have tried the below method which is time consuming
UIImageView *importMediaSaveImage=[[[UIImageView alloc] init] autorelease];
importMediaSaveImage.frame=CGRectMake(0, 0, 200,135 );
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
UIImage *images;
if (iref) {
images = [UIImage imageWithCGImage:iref];
}
NSData *data = [self photolibImageThumbNailData:images];
importMediaSaveImage.image = [UIImage imageWithData:data];
etc....
photolibImageThumbNailData
-(NSData *)photolibImageThumbNailData:(UIImage *)image{
// begin an image context that will essentially "hold" our new image
UIGraphicsBeginImageContext(CGSizeMake(200.0,135.0));
// now redraw our image in a smaller rectangle.
[image drawInRect:CGRectMake(0.0, 0.0, 200.0, 135.0)];
// make a "copy" of the image from the current context
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// now grab the PNG representation of our image
NSData *thumbData = UIImagePNGRepresentation(newImage);
return thumbData;
}
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您在这里可以做的不多......因为这是我们从 ALAsset 获得的仅有的两个选项。您将不得不在质量或时间上做出妥协。如果您使用的是自己存储在库中的图像,那么您可以在存储之前调整它们的大小,使其小一些,以提高处理速度。
i don't think there is much you can do here.. as those are the only two options we have from ALAsset. you will have to compromise either on quality or time. If you are using the images that you have yourself stored in the library then you can re size them before storing to be a bit smaller to increase the speed of the process.
您还应该尝试 [rep fullScreenImage] 以获得性能更好的表格视图,但图像质量比缩略图更好。
You should also try [rep fullScreenImage] for a better performant table view but an image with better quality than thumbnail.
您可以使用
CGImageRef iref = [myassetspectRatioThumbnail];
,您的缩略图看起来好多了!
You can use
CGImageRef iref = [myasset aspectRatioThumbnail];
and your thumbnail look much better !