从tif,jpg和psd图像获取剪辑路径 [英] Getting clip paths from tif,jpg and psd images

查看:88
本文介绍了从tif,jpg和psd图像获取剪辑路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(请在此处找到代码快照)-> 1 .您好,所以我有一些配置了剪切路径的tif和psd图像.我想做的是从Java中提取它们.所以我使用@haraldk设计的十二个猴子库.但我不能走这条路.从readPath()函数.这是因为,我从bufferedImage缓冲区获得的imageinputstream全部为零.我不知道为什么会这样.该缓冲区一直有效,直到ImageIO.createImageInputStream(source).(请参考下面链接中的代码快照).但在createimageinputstream()之后,缓冲区全为零.还有一件事,这仅适用于jpg和tiff.但是对于psd图像,我什至没有得到ByteArrayOutputStream,因为imageIO不支持psd图像.谁能帮助我?谢谢你.代码快照在下面的链接中

(Please find the code snapshot here)-> 1. Hello so i have some tif and psd images that have clipping paths configured. what I want to do is, to extract them from java. so I use twelvemonkeys library that @haraldk has designed. but i am not able to get the paths. from the readPath() function. that is because, the imageinputstream that i get from the bufferedimage the buffer is all zeroes. i dont know why it happens. the buffer is valid untill ImageIO.createImageInputStream(source).(please refer the code snapshot in the link below). but after createimageinputstream(), the buffer has all zeroes. one more thing, this only works for jpg and tiffs. but for psd images i am not even getting the ByteArrayOutputStream as imageIO does not support psd images. can any one plz help me? thank you. the code snapshot is in the link below

推荐答案

我不知道屏幕快照中的所有代码是做什么的,因为它不完整,但是:您需要创建 ImageInputStream 从原始文件内容.(IMO)非常简单.:-)

I have no idea what all that code in your screenshot does, as it is incomplete, but: You need to create the ImageInputStream from the original file contents. It's (IMO) quite straightforward. :-)

要么,读取图像并应用路径:

Either, read the image with the path applied:

try (ImageInputStream stream = ImageIO.createImageInputStream(new File("image_with_path.jpg")) {
    BufferedImage image = Paths.readClipped(stream);

    // Do something with the clipped image...
}

或分别读取图像和路径(这基本上是 readClipped(stream)的作用:

Or read the image and path separately (this is basically what readClipped(stream) does:

try (ImageInputStream stream = ImageIO.createImageInputStream(new File("image_with_path.jpg")) {
    Shape clip = Paths.readPath(stream);
    stream.seek(0);
    BufferedImage image = ImageIO.read(stream);

    if (clip != null) {
        image = Paths.applyClippingPath(clip, image);
    }

    // Do something with the clipped image...
}

我认为您的代码不起作用,因为您首先读取图像(使用一些未公开的代码),然后仅将像素数据写入临时流,然后尝试从那里获取路径.但是在 BufferedImage 中没有路径信息,因此路径信息丢失".在此操作中.同样,您需要从原始文件内容中获取它.

I think your code does not work because you first read the image (using some non-disclosed code), then write only the pixel data to a temporary stream, and try to get the paths from there. But there are no path information in the BufferedImage, so the path information is "lost" in this operation. Again, you need to get it from the original file contents.

这篇关于从tif,jpg和psd图像获取剪辑路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆