基于MIDP2.0实现图片的缩放功能[6]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

                    // now loop from srcY to srcY2 and add up the values for
                    // each channel
                    do
                    {
                        argb = tmpPixels[x + srcY * destW];
                        a += ((argb & 0xff000000) >> 24); // alpha channel
                        r += ((argb & 0x00ff0000) >> 16); // red channel
                        g += ((argb & 0x0000ff00) >> 8); // green channel
                        b += (argb & 0x000000ff); // blue channel
                        ++count; // count the pixel
                        ++srcY; // move on to the next pixel
                    } while (srcY <= srcY2
                            && x + srcY * destW < tmpPixels.length);

                    // average out the channel values
                    a /= count;
                    a = (a > 255) ? 255 : a;
                    r /= count;
                    r = (r > 255) ? 255 : r;
                    g /= count;
                    g = (g > 255) ? 255 : g;
                    b /= count;
                    b = (b > 255) ? 255 : b;

                    // recreate color from the averaged channels and place it
                    // into the destination buffer
                    destPixels[x + destY * destW] = ((a << 24) | (r << 16)
                            | (g << 8) | b);
                }
            }
        }

        // return a new image created from the destination pixel buffer
        return drawPixels(destPixels, destW, destH);
    }

}

    有兴趣的网友可以仔细研究一下。我准备了一个图片,然后写了一个测试的MIDlet。下面是效果对比。


 

本文关键:基于MIDP2.0实现图片的缩放功能
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top