[ 
https://issues.apache.org/jira/browse/PDFBOX-4974?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17214096#comment-17214096
 ] 

Robert Fink edited comment on PDFBOX-4974 at 10/14/20, 5:51 PM:
----------------------------------------------------------------

There is a method getUrl() but it returns null.
 This is quite obvious cause the WriteableImage is not created from a specified 
URL.
 Instead it's created from a byte array.

To illustrate this here's the code:
{code:java}
// Image with red, green, blue bands
WritableImage writableImage = new WritableImage(width, height);
PixelWriter pixelWriter = writableImage.getPixelWriter();
PixelFormat<ByteBuffer> pixelFormat = PixelFormat.getByteRgbInstance();
int bandCount = 3;
int writableImageBufferSize = (width * height) * bandCount;
byte[] writableImageBuffer = new byte[writableImageBufferSize];
pixelWriter.setPixels(0, 0, width, height, pixelFormat, writableImageBuffer, 0, 
width * bandCount);
{code}
 
{code:java}
// Image with blue, green, red and alpha bands
WritableImage writableImage = new WritableImage(width, height);
PixelWriter pixelWriter = writableImage.getPixelWriter();
PixelFormat<ByteBuffer> pixelFormat = PixelFormat.getByteBgraInstance();
int bandCount = 4;
int writableImageBufferBufferSize = (width * height) * bandCount;
byte[] writableImageBuffer = new byte[writableImageBufferBufferSize];
pixelWriter.setPixels(0, 0, width, height, pixelFormat, writableImageBuffer, 0, 
width * bandCount);
{code}
The PixelFormat.getByteBgraInstance() is not ideal. There should be the 
PixelFormat.getByteArgbInstance() too.
 However I am on the mailing list of the JavaFX team to ask to implement such a 
method.


was (Author: robertoni):
There is a method getUrl() but it returns null.
This is quite obvious cause the WriteableImage is not created from a specified 
URL.
Instead it's created from a byte buffer.
To illustrate this here's the code:
{code:java}
// Image with red, green, blue bands
WritableImage writableImage = new WritableImage(width, height);
PixelWriter pixelWriter = writableImage.getPixelWriter();
PixelFormat<ByteBuffer> pixelFormat = PixelFormat.getByteRgbInstance();
int bandCount = 3;
int writableImageBufferSize = (width * height) * bandCount;
byte[] writableImageBuffer = new byte[writableImageBufferSize];
pixelWriter.setPixels(0, 0, width, height, pixelFormat, writableImageBuffer, 0, 
width * bandCount);
{code}
 
{code:java}
// Image with blue, green, red and alpha bands
WritableImage writableImage = new WritableImage(width, height);
PixelWriter pixelWriter = writableImage.getPixelWriter();
PixelFormat<ByteBuffer> pixelFormat = PixelFormat.getByteBgraInstance();
int bandCount = 4;
int writableImageBufferBufferSize = (width * height) * bandCount;
byte[] writableImageBuffer = new byte[writableImageBufferBufferSize];
pixelWriter.setPixels(0, 0, width, height, pixelFormat, writableImageBuffer, 0, 
width * bandCount);
{code}
The PixelFormat.getByteBgraInstance() is not ideal. There should be the 
PixelFormat.getByteArgbInstance() too.
However I am on the mailing list of the JavaFX team to ask to implement such a 
method.

> PDImageXObject based on WritableImage
> -------------------------------------
>
>                 Key: PDFBOX-4974
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4974
>             Project: PDFBox
>          Issue Type: New Feature
>          Components: PDModel
>    Affects Versions: 2.0.0
>            Reporter: Robert Fink
>            Priority: Major
>              Labels: javafx
>
> The goal is to work with a WritableImage from JavaFX in addition to a 
> BufferedImage from Swing.
> My proposal for a new feature are the following. 
> To extend the factory classes:
>  - CCITTFactory by the method:
>  createFromImage(PDDocument document, WritableImage image)
>  - JPEGFactory by the methods:
>  createFromImage(PDDocument document, WritableImage image)
>  createFromImage(PDDocument document, WritableImage image, float quality)
>  createFromImage(PDDocument document, WritableImage image, float quality, int 
> dpi)
>  - LosslessFactory by methods:
>  createFromImage(PDDocument document, WritableImage image)
> To extend the PDImageXObject class:
>  * by the methods:
> getWritableImage()
> getWritableImage(Rectangle region, int subsampling)
> Until now there is a need to use the class SwingFXUtils to do the conversion 
> from WritableImage to BufferedImage or vice versa.
>  This new feature should come in handy for all JavaFX developers.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to