我是靠谱客的博主 彩色自行车,最近开发中收集的这篇文章主要介绍blackberry黑莓的图片缩放,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

今天群里有高人帖的,赶紧存了,未测试过。 

 

public static Bitmap ZoomImage(Image src, int desW, int desH) {
         int srcW = src.getWidth(); // 原始图像宽
         int srcH = src.getHeight(); // 原始图像高
         int[] srcBuf = new int[srcW * srcH]; // 原始图片像素信息缓存
         src.getRGB(srcBuf, 0, srcW, 0, 0, srcW, srcH);
         // 计算插值表
         int[] tabY = new int[desH];
         int[] tabX = new int[desW];
         int sb = 0;
         int db = 0;
         int tems = 0;
         int temd = 0;
         int distance = srcH > desH ? srcH : desH;
         for (int i = 0; i <= distance; i++) { /* 垂直方向 */
             tabY[db] = sb;
             tems += srcH;
             temd += desH;
             if (tems > distance) {
                 tems -= distance;
                 sb++;
             }
             if (temd > distance) {
                 temd -= distance;
                 db++;
             }
         }
         sb = 0;
         db = 0;
         tems = 0;
         temd = 0;
         distance = srcW > desW ? srcW : desW;
         for (int i = 0; i <= distance; i++) { /* 水平方向 */
             tabX[db] = (short) sb;
             tems += srcW;
             temd += desW;
             if (tems > distance) {
                 tems -= distance;
                 sb++;
             }
             if (temd > distance) {
                 temd -= distance;
                 db++;
             }
         }
         // 生成放大缩小后图形像素buf
         int[] desBuf = new int[desW * desH];
         int dx = 0;
         int dy = 0;
         int sy = 0;
         int oldy = -1;
         for (int i = 0; i < desH; i++) {
             if (oldy == tabY[i]) {
                 System.arraycopy(desBuf, dy - desW, desBuf, dy, desW);
             } else {
                 dx = 0;
                 for (int j = 0; j < desW; j++) {
                     desBuf[dy + dx] = srcBuf[sy + tabX[j]];
                     dx++;
                 }
                 sy += (tabY[i] - oldy) * srcW;
             }
             oldy = tabY[i];
             dy += desW;
         }
        
         // 生成图片
         //desImg = Image.createRGBImage(desBuf, desW, desH, true);
         //return desImg;
         Bitmap bmp = new Bitmap(desW, desH);
   bmp.setARGB(desBuf, 0, desW, 0, 0, desW, desH);
   return bmp;
     }

最后

以上就是彩色自行车为你收集整理的blackberry黑莓的图片缩放的全部内容,希望文章能够帮你解决blackberry黑莓的图片缩放所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部