dragon66 / icafe

Java library for reading, writing, converting and manipulating images and metadata
Eclipse Public License 1.0
204 stars 58 forks source link

Writing byte array or int array to a file #102

Closed lanthale closed 3 years ago

lanthale commented 3 years ago

I have seen that there is a method for writing image data with provided byte array / int array. But this method is protected and not public. The reason why I am asking is that I am a JavaFX developer and want to write files. Normally in JavaFX you have the Image class and you can get out of every image a byte array or a int array of ARGB or BRGA or other types. But I need the method to write it to an image file. Actually I am using a workaround to convert the JavaFX image to a bufferedimage and than write it with iCafe. But this does not work if the colorspace is not RGB (images with purple tints).

Is it possible to get such an interface so that I do not need to convert the image data via BufferedImage ?

dragon66 commented 3 years ago

@lanthale The original method was made protected as I believe Image/BufferedImage are standard Java image wrappers and it would be easier for the user to use the library.

I don't feel like exposing it directly from icafe but if it makes sense for you to write directly using that method, the most straight forward way I can think of is to subclass each writer and make the method public. You don't need to do other changes besides call the base class method.

The drawback of this is you can't use the common interface to write image and have to instantiate individual writer yourself but that won't be a big issue given the benefit you have writing directly with the method.

Note the method uses RGBA int array explicitly. You have to make sure your data is in the correct format.

Wen

lanthale commented 3 years ago

thank you for the information. I will do that.