Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image J2ME中的图像重缩放_Image_Java Me - Fatal编程技术网

Image J2ME中的图像重缩放

Image J2ME中的图像重缩放,image,java-me,Image,Java Me,我正在使用以下代码调整鸟图像的大小: 专用图像大小图像(图像src){ int srcWidth=src.getWidth(); int srchheight=src.getHeight(); int screenWidth=getWidth()/3; int screenHeight=getHeight()/3; Image tmp=Image.createImage(屏幕宽度、高度); Graphics g=tmp.getGraphics(); int ratio=(srcWidth>16)

我正在使用以下代码调整鸟图像的大小:

专用图像大小图像(图像src){

int srcWidth=src.getWidth();
int srchheight=src.getHeight();
int screenWidth=getWidth()/3;
int screenHeight=getHeight()/3;
Image tmp=Image.createImage(屏幕宽度、高度);
Graphics g=tmp.getGraphics();
int ratio=(srcWidth>16),0,Graphics.LEFT | Graphics.TOP);
pos+=比率;
}
Image resizedImage=Image.createImage(屏幕宽度、屏幕高度);
g=resizedImage.getGraphics();
比率=(srchheight>16),Graphics.LEFT | Graphics.TOP);
pos+=比率;
}
返回resizedImage;
}


该图像已调整大小,但同时具有白色背景,如图所示。如何仅获取具有透明背景的已调整大小的图像

这是我一直在使用的图像缩放函数。包括透明度。可在此处找到:


}

谢谢您的回复。。我试过这个方法。现在我可以看到黑色像素而不是白色像素作为背景。。它不是父母,这很奇怪。我已经成功地将它用于我们的最新游戏piratediamonds.com,包括8位和24位PNG文件。记住在return Image.createRGBImage方法中将“true”作为最后一个参数。它现在可以工作了。。但在设备上,调整大小需要时间。有什么算法能让它更快吗?我不这么认为。该函数已经是优化的变体之一。
    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;
public Image scale(Image original, int newWidth, int newHeight) {

 int[] rawInput = new int[original.getHeight() * original.getWidth()];
 original.getRGB(rawInput, 0, original.getWidth(), 0, 0, original.getWidth(), original.getHeight());

 int[] rawOutput = new int[newWidth * newHeight];

 // YD compensates for the x loop by subtracting the width back out
 int YD = (original.getHeight() / newHeight) * original.getWidth() - original.getWidth();
 int YR = original.getHeight() % newHeight;
 int XD = original.getWidth() / newWidth;
 int XR = original.getWidth() % newWidth;
 int outOffset = 0;
 int inOffset = 0;

 for (int y = newHeight, YE = 0; y > 0; y--) {
   for (int x = newWidth, XE = 0; x > 0; x--) {
     rawOutput[outOffset++] = rawInput[inOffset];
     inOffset += XD;
     XE += XR;
     if (XE >= newWidth) {
       XE -= newWidth;
       inOffset++;
     }
   }
   inOffset += YD;
   YE += YR;
   if (YE >= newHeight) {
     YE -= newHeight;
     inOffset += original.getWidth();
   }
 }
 rawInput = null;
 return Image.createRGBImage(rawOutput, newWidth, newHeight, true);