0

我遇到了这段代码

do {
    if (higherQuality && w > targetWidth) {
        w /= 2;
        if (w < targetWidth) {
            w = targetWidth;
        }
    }

    if (higherQuality && h > targetHeight) {
        h /= 2;
        if (h < targetHeight) {
            h = targetHeight;
        }
    } 
    BufferedImage tmp = new BufferedImage(w, h, type);
    Graphics2D g2 = tmp.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint);
    g2.drawImage(ret, 0, 0, w, h, null);
    g2.dispose();

    ret = tmp;
} while (w != targetWidth || h != targetHeight);

我不明白这些 if 条件的含义

if (higherQuality && w > targetWidth)

if (higherQuality && h > targetHeight)

它对我来说类似于 C 的&variable引用运算符。我是java新手,但我知道它不支持这样的东西,除了标准的按位和逻辑AND之外,我无法在java中搜索出任何其他含义。我将不胜感激任何解释。谢谢你。

4

3 回答 3

4

&并且>HTML 字符引用;看起来上面的代码在你找到它的任何网站上都被错误地编码了。

所以作为参考,这个:

if (higherQuality && w > targetWidth)

应该显示为:

if (higherQuality && w > targetWidth)
于 2012-05-28T17:37:46.283 回答
0

解码 HTLM 后,代码读取

if (higherQuality && h > targetHeight)

然后&&是 Java 的条件与运算符。

于 2012-05-28T17:38:18.503 回答
0

有人只是偶然对它进行了双重 HTML 编码。它们实际上只是常规运算符,代码应如下所示:

do {
    if (higherQuality && w > targetWidth) {
        w /= 2;
        if (w < targetWidth) {
            w = targetWidth;
        }
    }

    if (higherQuality && h > targetHeight) {
        h /= 2;
        if (h < targetHeight) {
            h = targetHeight;
        }
    }
    BufferedImage tmp = new BufferedImage(w, h, type);
    Graphics2D g2 = tmp.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint);
    g2.drawImage(ret, 0, 0, w, h, null);
    g2.dispose();

    ret = tmp;
} while (w != targetWidth || h != targetHeight);
于 2012-05-28T17:39:15.340 回答