在j2me中如何使图片填充全屏
1个回答
展开全部
没有自带的方法,我写一个给你用吧,传入图片和屏幕的宽和高,返回拉伸成屏幕大小的image
public Image resizeImg(Image img, int newWidth, int newHeight) {
int imgW = img.getWidth();
int imgH = img.getHeight();
int[] srcPixels = new int[imgW * imgH];
int[] destPixels = new int[newWidth * newHeight];
img.getRGB(srcPixels, 0, imgW, 0, 0, imgW, imgH);
int srcX;
int srcY;
for (int y = 0; y < newHeight; ++y) {
for (int x = 0; x < newWidth; ++x) {
srcX = (x * imgW) / newWidth;
srcY = (y * imgH) / newHeight;
destPixels[x + y * newWidth] = srcPixels[srcX + srcY * imgW];
}
}
return Image.createRGBImage(destPixels, newWidth, newHeight, true);
}
public Image resizeImg(Image img, int newWidth, int newHeight) {
int imgW = img.getWidth();
int imgH = img.getHeight();
int[] srcPixels = new int[imgW * imgH];
int[] destPixels = new int[newWidth * newHeight];
img.getRGB(srcPixels, 0, imgW, 0, 0, imgW, imgH);
int srcX;
int srcY;
for (int y = 0; y < newHeight; ++y) {
for (int x = 0; x < newWidth; ++x) {
srcX = (x * imgW) / newWidth;
srcY = (y * imgH) / newHeight;
destPixels[x + y * newWidth] = srcPixels[srcX + srcY * imgW];
}
}
return Image.createRGBImage(destPixels, newWidth, newHeight, true);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询