经典的图像缩放.doc_第1页
经典的图像缩放.doc_第2页
经典的图像缩放.doc_第3页
经典的图像缩放.doc_第4页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

几个经典的图像缩放的函数收集了几个图像缩放的函数,可能实现的方式很多,感觉这几个不错的,分享下说明:以下函数都是基于MIDP2.0的,缩放后保留透明色。代码1,函数 resizeImagepublic static Image resizeImage(Image src, int destW, int destH) int srcW = src.getWidth(); int srcH = src.getHeight(); / create pixel arrays int destPixels = new intdestW * destH; / array to hold destination / pixels int srcPixels = new intsrcW * srcH; / array with sources pixels src.getRGB(srcPixels, 0, srcW, 0, 0, srcW, srcH); / simple point smapled resizing / loop through the destination pixels, find the matching pixel on / the source and use that for (int destY = 0; destY destH; +destY) for (int destX = 0; destX desH ? srcH : desH; for (int i = 0; i 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) tems -= distance; sb+; if (temd distance) temd -= distance; db+; / 生成放大缩小后图形像素buf int desBuf = new intdesW * desH; int dx = 0; int dy = 0; int sy = 0; int oldy = -1; for (int i = 0; i desH; i+) if (oldy = tabYi) System.arraycopy(desBuf, dy - desW, desBuf, dy, desW); else dx = 0; for (int j = 0; j 0; y-) for (int x = newWidth, XE = 0; x 0; x-) rawOutputoutOffset+ = rawInputinOffset; inOffset += XD; XE += XR; if (XE = newWidth) XE -= newWidth; inOffset+; inOffset += YD; YE += YR; if (YE = newHeight) YE -= newHeight; inOffset += original.getWidth(); return Image.createRGBImage(rawOutput, newWidth, newHeight, true); 我将100*100的图放大到200*200后对比了一下,ZoomImage生成的图片和另外两个函数生成的图像有点区别,感觉ZoomImage的效果好一点。再放大点就基本一样了看不出区别了。代码4 /*图像变换*/ public Image scaleImage(Image src,int scales1,int scales2) return transImage(src,src.getWidth()*scales1/scales2,src.getHeight()*scales1/scales2); public Image transImage(Image src, int w, int h) int srcW = src.getWidth(); int srcH = src.getHeight(); int dstW=w,dstH=h; Image tmp = Image.createImage(dstW, srcH); Graphics g = tmp.getGraphics(); int scale=16; int delta = (srcW scale) / dstW;/扫描长度 int pos = delta / 2;/扫描位置 for (int x = 0; x scale), 0, Graphics.LEFT | Graphics.TOP); pos += delta; Image dst = Image.createImage( dstW, dstH); g = dst.getGraphics(); delta = (srcH sca

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论