以编程方式创建图像的缩略图

时间:2011-04-11 12:46:35

标签: iphone

在我的应用程序中我从服务器获取图像,我能够在图像视图中显示图像.... 但现在我想在桌面视图中存储从服务器获取的图像,并在单击表格视图单元格时显示它们。我想要的是如何制作图像的缩略图,以便在表格视图单元格中显示它。如果我直接在表格视图单元格中显示图像,那就是出现笨拙的东西......因为我想制作缩略图该图像并在表格视图单元格中显示...

任何人都可以帮我如何以编程方式创建图像的缩略图......

2 个答案:

答案 0 :(得分:2)

答案 1 :(得分:0)

- (void) createThumbView { float y_axis = Set y axis;

int x = 0;

int totalImgs = total images;

int tempCnt = 0;

for (int i = 0; i < totalImgs;)
{
    float x_axis = set x axis;

    int loopCount = 0;

    if (totalImgs - tempCnt >= (no of images in row))
    {
        loopCount = (no of images in row);
    }
    else
    {
        loopCount = totalImgs % (no of images in row);
    }

    for (int j = 0; j < loopCount; j++)
    {
        MasksData *mData = [masksList objectAtIndex:x];

        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(x_axis, y_axis, width, height);
        [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@.png",mData.bgImage]] forState:UIControlStateNormal];
        btn.backgroundColor = [UIColor  clearColor];
        btn.tag = x;
        [scroll View addSubview:btn];

        //photoCount++;
        x_axis += width + some space;

        tempCnt++;
        i++;
        x++;
    }

    y_axis += height + some space;

    scroll View.contentSize = CGSizeMake(320.0, y_axis);
}