khmahdi
پنج شنبه 20 خرداد 1389, 22:37 عصر
يه تابع براي resize كردن image ، مبتديه ولي خيلي مفيد
public Image rescaleImage(Image srcImg, int newWidth, int newHeight) {
int dx=0, dy=0, xx=0, yy=0;
int out[] = new int[newWidth*newHeight];
int x = srcImg.getWidth();
int y = srcImg.getHeight();
int[] ini = new int[srcImg.getWidth()*srcImg.getHeight()];
srcImg.getRGB(ini,0,srcImg.getWidth(),0,0,srcImg.g etWidth(),srcImg.getHeight());
for (yy = 0; yy < newHeight; yy++) {
dy = yy * y / newHeight;
for (xx = 0; xx < newWidth; xx++) {
dx = xx * x / newWidth;
out[(newWidth*yy)+xx]=ini[(x*dy)+dx];
}
}
return Image.createRGBImage(out,newWidth,newHeight,true);
}
public Image rescaleImage(Image srcImg, int newWidth, int newHeight) {
int dx=0, dy=0, xx=0, yy=0;
int out[] = new int[newWidth*newHeight];
int x = srcImg.getWidth();
int y = srcImg.getHeight();
int[] ini = new int[srcImg.getWidth()*srcImg.getHeight()];
srcImg.getRGB(ini,0,srcImg.getWidth(),0,0,srcImg.g etWidth(),srcImg.getHeight());
for (yy = 0; yy < newHeight; yy++) {
dy = yy * y / newHeight;
for (xx = 0; xx < newWidth; xx++) {
dx = xx * x / newWidth;
out[(newWidth*yy)+xx]=ini[(x*dy)+dx];
}
}
return Image.createRGBImage(out,newWidth,newHeight,true);
}