java - 在假想的水平线上翻转像素

标签 java

我需要将图像翻转到假想的水平线上,但不知道该怎么做。

这是我当前的代码,Eclipse 告诉我,hold 的值没有被使用,但我不明白为什么没有。感谢所有帮助。

public static void flipH(Picture p){

    int height= p.getHeight();
    int width= p.getWidth();

    Pixel empty= new Pixel(v, 0, 0);
    Pixel hold= new Pixel(v, 0, 0);

    for(int i=0; i< height; i++) {
        for(int j=0, r=width-1; j<width/2 && r>width/2; j++, r--) {
            empty= p.getPixel(i, j);
            hold = p.getPixel(i, r);
            hold= empty;                
        }
    }               
}

最佳答案

empty和hold只是引用,又名指针,指向真实对象的箭头。 分配空并保持指向某个像素永远不会改变该像素。 要交换两个像素,您需要类似...

    int a = p.getColorOfPixel(x, y1);
    int b = p.getColorOfPixel(x, y2);
    p.setColorOfPixel(x, y1, b);
    p.setColorOfPixel(x, y2, a);

关于java - 在假想的水平线上翻转像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43429673/

相关文章:

java - 如何使用 BufferedWriter 将二维数组保存到文本文件中?

java - 从 python 中的 java 代码重现 uuid

java - 配置 Spring Batch 而不保留元数据

java - 将 InputStream 作为参数传递给 Web 服务

java - Apache Http UrlBuilder 从 URL 中剥离 API 版本

java - 带计时器的 ServletContextListener 未在控制台中显示输出

java - 如何检查值是否存在/为什么 ResultSet 在 SQLite 中关闭?

java - 为什么要为 Threads 创建一个匿名的 Runnable 子类?

java - SWT:如何为文本字段重新创建默认上下文菜单

java - 缩小 Joda-Time 部分的范围