0
我使用以下代码大小调整鸟图像:重新缩放图像在J2ME
私人图片resizeImage(图像SRC){
int srcWidth = src.getWidth(); int srcHeight = src.getHeight(); int screenWidth=getWidth()/3; int screenHeight=getHeight()/3; Image tmp = Image.createImage(screenWidth, srcHeight); Graphics g = tmp.getGraphics(); int ratio = (srcWidth << 16)/screenWidth; int pos = ratio/2; //Horizontal Resize for (int x = 0; x < screenWidth; x++) { g.setClip(x, 0, 1, srcHeight); g.drawImage(src, x - (pos >> 16), 0, Graphics.LEFT | Graphics.TOP); pos += ratio; } Image resizedImage = Image.createImage(screenWidth, screenHeight); g = resizedImage.getGraphics(); ratio = (srcHeight << 16)/screenHeight; pos = ratio/2; //Vertical resize for (int y = 0; y < screenHeight; y++) { g.setClip(0, y, screenWidth, 1); g.drawImage(tmp, 0, y - (pos >> 16), Graphics.LEFT | Graphics.TOP); pos += ratio; } return resizedImage;
}
的图像被调整大小,但它具有白色背景,如图所示。如何获得只有透明背景调整大小的图像..?
感谢乌拉圭回合的答复..我尝试这个方法。现在我可以看到黑色像素,而不是白色像素作为背景。它不是透明的。 – Andy
这很奇怪。我已经成功地将它用于我们的最新游戏piratediamonds.com,它们都带有8位和24位PNG文件。请记住将“true”作为返回Image.createRGBImage方法中的最后一个参数。 –
现在它的工作..但在设备上它需要时间来调整大小。任何算法,使其更快? – Andy