• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            逛奔的蝸牛

            我不聰明,但我會(huì)很努力

               ::  :: 新隨筆 ::  ::  :: 管理 ::
            1. Bilinear
            2. BiCubic
            3. Area_Average
            4. Progressive Bilinear
            當(dāng)圖片縮小到原圖的一半以下時(shí),bilinear的效果就不好了,再小下去,bicubic的也不夠好,最好的效果是area_average算法,但是這個(gè)需要花太多的時(shí)間,可以使用改進(jìn)過(guò)的bilinear算法,效果跟area average差不多,速度在bilinear和bicubic之間,但是當(dāng)圖片非常大,綻放到非常小時(shí),花的時(shí)間比bicubic多得多,但是比area average少得多,效果與area average差不多,還是不錯(cuò)的

            Progressive Bilinear Scaling

            We know that a significant problem with the quality of the bilinear approach occurs when the downscale is by more than 50 percent. So what if we compen- sated for that problem by scaling iteratively toward the final size, scaling down by exactly 50 percent each time until the final iteration, when we scale by 50 percent or less? Then we would account for all of the pixels along the way that should figure into the final image. 

                // 縮小圖片,縮小時(shí)可以使用改進(jìn)過(guò)的bilinear, bicubic插值算法

                // 但是轉(zhuǎn)換透明圖片時(shí)如果使用單緩沖區(qū)會(huì)出問(wèn)題,這時(shí)每次都要?jiǎng)?chuàng)建一個(gè)緩沖區(qū)才可以

                public static BufferedImage getFasterDownScaledInstance(BufferedImage img,

                                                                        int targetWidth,

                                                                        int targetHeight,

                                                                        Object hint,

                                                                        boolean progressive) {

                    int type = (img.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB

                            : BufferedImage.TYPE_INT_ARGB;

                    BufferedImage ret = (BufferedImage) img;

                    BufferedImage scratchImage = null;

                    Graphics2D g2d = null;

                    int w = 0, h = 0;

                    int prevW = ret.getWidth();

                    int prevH = ret.getHeight();


                    if (progressive) {

                        // Use multistep technique: start with original size,

                        // then scale down in multiple passes with drawImage()

                        // until the target size is reached

                        w = img.getWidth();

                        h = img.getHeight();

                    } else {

                        // Use one-step technique: scale directly from original

                        // size to target size with a single drawImage() call

                        w = targetWidth;

                        h = targetHeight;

                    }


                    do {

                        if (targetWidth < img.getWidth() && progressive && w > targetWidth) {

                            // 如果是縮小,寬縮小為原來(lái)的一半

                            w >>>= 1;

                            w = (w < targetWidth) ? targetWidth : w;

                        } else {

                            w = targetWidth;

                        }


                        if (targetHeight < img.getHeight() && progressive && h > targetHeight) {

                            // 如果是縮小,高縮小為原來(lái)的一半

                            h >>>= 1;

                            h = (h < targetHeight) ? targetHeight : h;

                        } else {

                            h = targetHeight;

                        }


                        if (scratchImage == null) {

                            // Use a single scratch buffer for all iterations

                            // and then copy to the final, correctly sized image before

                            // returning

                            scratchImage = new BufferedImage(w, h, type);

                            g2d = scratchImage.createGraphics();

                        } else if (type == BufferedImage.TYPE_INT_ARGB && scratchImage != null && g2d != null) {

                            // 透明圖片不能使用單緩存

                            g2d.dispose();

                            scratchImage = new BufferedImage(w, h, type);

                            g2d = scratchImage.createGraphics();

                        }


                        g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint);

                        g2d.drawImage(ret, 0, 0, w, h, 0, 0, prevW, prevH, null);

                        prevW = w;

                        prevH = h;

                        ret = scratchImage;

                    } while (w != targetWidth || h != targetHeight);


                    if (g2d != null) {

                        g2d.dispose();

                    }


                    // If we used a target size, the results into it

                    if (targetWidth != ret.getWidth() || targetHeight != ret.getHeight()) {

                        scratchImage = new BufferedImage(targetWidth, targetHeight, type);

                        g2d = scratchImage.createGraphics();

                        g2d.drawImage(ret, 0, 0, null);

                        g2d.dispose();

                        ret = scratchImage;

                    }

                    return ret;

                }

            posted on 2011-01-09 18:20 逛奔的蝸牛 閱讀(4265) 評(píng)論(0)  編輯 收藏 引用 所屬分類: Java
            欧美噜噜久久久XXX| 精品无码久久久久国产动漫3d| 久久久久这里只有精品| 久久99热国产这有精品| 99久久精品九九亚洲精品| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区| 国产精品久久自在自线观看| 久久久久亚洲AV无码永不| 亚洲国产成人久久精品动漫| 日韩va亚洲va欧美va久久| 久久久久久亚洲AV无码专区| 久久99久久成人免费播放| 亚洲欧洲精品成人久久曰影片| 国产精品久久久久久影院 | 国产叼嘿久久精品久久| 久久天天躁狠狠躁夜夜2020| 久久久免费精品re6| 亚洲一级Av无码毛片久久精品| 99精品久久久久中文字幕| 久久亚洲精品国产亚洲老地址| 国产欧美一区二区久久| 狠狠色婷婷久久一区二区| 亚洲综合久久综合激情久久| 久久影院综合精品| 麻豆久久久9性大片| 99久久国产主播综合精品 | 久久综合九色综合久99| 无码精品久久一区二区三区| 久久99国产精品一区二区| 性欧美丰满熟妇XXXX性久久久 | 精品久久久久久国产| 久久精品国产精品亚洲下载 | 久久精品国产精品亚洲精品| 久久久久久A亚洲欧洲AV冫| 久久免费精品视频| 99久久精品国内| 久久精品国产亚洲av水果派| 欧美黑人又粗又大久久久| 色欲av伊人久久大香线蕉影院 | 久久久精品国产| 2021国产精品久久精品|