资源简介
个人使用双线性性插值实现了图形的伸缩。输入参数为图形的像素矩阵
代码片段和文件信息
//////////////////获取图像像素矩阵\\\\\\\\\\\\\\\\\\\
private int[]getPixArray(Image imint wint h){
int[] pix=new int[w*h];
PixelGrabber pg=null;
try{
pg = new PixelGrabber(im 0 0 w h pix 0 w);
if(pg.grabPixels()!=true)
try{
throw new java.awt.AWTException(“pg error“+pg.status());
}catch(Exception eq){
eq.printStackTrace();
}
} catch(Exception ex){
ex.printStackTrace();
}
return pix;
}
////////////图形伸缩, 输入参数为图象像素矩阵,和横向,纵向拉伸比例参数\\\\\\\\\\\\\\\\\\\
private int[] stretch(int[] ImageSource float xscale float yscale){
//////////使用双线性插值算法\\\\\\\\\\\\\\\\\\\
int[]flipArray = null;
int i j x0 y0 alpha r g b;
ColorModel colorModel=ColorModel.getRGBdefault();
float u v;
int width = (int) (w * xscale);
int height = (int) (h * yscale);
flipArray = new int[width * height];
if( ( ImageSource == null ) || ( xscale <=0 ) || ( yscale <= 0 ) )
return null;
for( j=0; j for(i=0; i x0 = (int) ( i / xscale);
y0 = (int) ( j / yscale );
u = i / xscale - x0;
v = j / yscale - y0;
if( ((x0 + 1) < w ) && (( y0+1 )< h ) ) {
/***** no use to get the alpha and RGB value to
* calculate the image pixel color value
*
int alpha00 = colorModel.getAlpha(ImageSource[x0 + y0*w]);
int r00 = colorModel.getRed(ImageSource[x0 + y0*w]);
int g00 = colorModel.getGreen(ImageSource[x0 + y0*w]);
int b00 = colorModel.getBlue(ImageSource[x0 + y0*w]);
int alpha10 = colorModel.getAlpha(ImageS
- 上一篇:DBSCAN聚类算法java实现
- 下一篇:glide jar包
评论
共有 条评论