如何改变影像的角度

时间:2019-04-24 05:25:53

标签: java image-processing

实际上,我正在开发需要更换房间地板的应用程序。应用程序的后端在java中。假设这是房间。

Room whose floor needs to be changed

Room after floor removed

Carpet which needs to be laid

Result after executing the code

我已使用photoshop之类的软件移除了房间的地板。现在,我需要为该图像添加新的地毯地板。地毯地板必须是动态的,用户可以选择任何地毯,并在渲染后替换图像。

import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class FloorChange {

    public static void main(String[] args) {
        int width = 1920; // width of the image
        int height = 1080; // height of the image

        // For storing image in RAM
        BufferedImage image = null;
        BufferedImage background = null;
        BufferedImage finalImage = null;

        // READ IMAGE
        try {
            File input_file = new File("room.png"); // image file path
            File floor_tile = new File("milkyway.jpg"); // image file path

            FloorChange floorChange = new FloorChange();
            image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
            background = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
            finalImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);


            System.out.println("Reading complete.");
        } catch (IOException e) {
            System.out.println("Error: " + e);
        }

        try {
            Graphics2D g = finalImage.createGraphics();

            g.drawImage(background, 0, 0, null);
            g.drawImage(image, 0, 0, null);
            File output_file = new File("floor1.png");

            ImageIO.write(finalImage, "png", output_file);
            System.out.println("Writing complete.");
        } catch (IOException e) {
            System.out.println("Error: " + e);
        }
    }

    private BufferedImage resizeImage(BufferedImage originalImage, int type) {
        int IMG_WIDTH = 1920;
        int IMG_CLAHEIGHT = 1080;
        BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_CLAHEIGHT, type);
        Graphics2D g = resizedImage.createGraphics();
        g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_CLAHEIGHT, null);
        g.dispose();
        return resizedImage;
    }

I have replaced the floor but the image was stretched and if I repeat the image it gives lines between each carpet. And also the perspective of the imag e is not proper.

0 个答案:

没有答案