2013-05-12 50 views
0

我知道retina设备上默认的图像是高档的,但默认缩放会使图像模糊。在Retina设备上放大图像

我想知道是否有一种方法可以在最近邻居模式下进行缩放,其中没有创建透明像素,而是每个像素乘以4,因此它看起来像是在非视网膜设备上。

我在说什么的例子可以在下面的图片中看到。 example http://cclloyd.com/downloads/sdfsdf.png

回答

0

CoreGraphics不会像这样做2倍缩放,你需要写一些显式像素映射逻辑来做这样的事情。以下是我用于执行此操作的一些代码,您当然需要填写详细信息,因为这将对像素的输入缓冲区进行操作,并将其写入输出缓冲区(像素大2倍)。

// Use special case "DOUBLE" logic that will simply duplicate the exact 
    // RGB value from the indicated pixel into the 2x sized output buffer. 

    int numOutputPixels = resizedFrameBuffer.width * resizedFrameBuffer.height; 

    uint32_t *inPixels32 = (uint32_t*)cgFrameBuffer.pixels; 
    uint32_t *outPixels32 = (uint32_t*)resizedFrameBuffer.pixels; 

    int outRow = 0; 
    int outColumn = 0; 

    for (int i=0; i < numOutputPixels; i++) { 
    if ((i > 0) && ((i % resizedFrameBuffer.width) == 0)) { 
     outRow += 1; 
     outColumn = 0; 
    } 

    // Divide by 2 to get the column/row in the input framebuffer 
    int inColumn = outColumn/2; 
    int inRow = outRow/2; 

    // Get the pixel for the row and column this output pixel corresponds to 
    int inOffset = (inRow * cgFrameBuffer.width) + inColumn; 
    uint32_t pixel = inPixels32[inOffset]; 

    outPixels32[i] = pixel; 

    //fprintf(stdout, "Wrote 0x%.10X for 2x row/col %d %d (%d), read from row/col %d %d (%d)\n", pixel, outRow, outColumn, i, inRow, inColumn, inOffset); 

    outColumn += 1; 
    } 

这当然代码取决于你生成像素的缓冲区,然后包装它备份到CFImageRef。但是,你可以找到所有的代码来轻松完成这种事情。