thuliobuarque / java2word

Automatically exported from code.google.com/p/java2word
0 stars 0 forks source link

Image from stream #85

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hello,
your generator is great. 
I have a suggestion for inserting images. Would be cool if it is possible to 
create Image from a Stream beside stored file. 
Now i have images stored in database, so i have to save them into filesystem 
and after then insert into word document.

Thanks,
Tony

Original issue reported on code.google.com by trumb...@gmail.com on 15 Feb 2012 at 8:42

GoogleCodeExporter commented 8 years ago
How do you read the image? into a InputStream? What DB id it?
if so, the thing now is convert from Inputstream to BufferedImage.

I didn't google hard but it is possible. Give it a shot if you want. This 
functionality would be very handy.

Classe Image in  java2word converts a "java.awt.image.BufferedImage" to 
Hexadecimal. So if you find out how to get it into a BufferedImage the rest is 
easy.

Thanks for the suggestion. I don't have any example image in a database now.

cheers
Leonardo

Original comment by leonardo...@gmail.com on 15 Feb 2012 at 1:10

GoogleCodeExporter commented 8 years ago
I have byte[], but it is not problem do a InputStream.

Now i just sort it out.

I explored your source and found out it is quite easy. I added other private 
Image constructor with 2 params - Image(String filename, InputStream is) and 
static method and static method from_STREAM(String filename, InputStream 
inputStream).

But would be much better it would be done on your side, due to future 
compatibility. And of course it can be useful for other.

Thanks for your reply.

Original comment by trumb...@gmail.com on 15 Feb 2012 at 1:31

GoogleCodeExporter commented 8 years ago
send me a patch and I apply to the code.
thanks a lot

Original comment by leonardo...@gmail.com on 15 Feb 2012 at 1:58

GoogleCodeExporter commented 8 years ago
Here are both new methods. 
Thanks.

  private Image(String filename, InputStream inputStream) {
      if (inputStream == null)
          throw new IllegalArgumentException("Can't create image - null input stream");
      if (filename == null || filename.length() < 3)
          throw new IllegalArgumentException("Can't create image - invalid filename");
      this.path = filename;
      try {
          this.bufferedImage = ImageIO.read(inputStream);
      } catch (IOException e) {
          throw new RuntimeException("Can't create ImageIO.", e);
      }
  }

  public static Image from_STREAM(String filename, InputStream inputStream)
  {
    return new Image(filename, inputStream);
  }

Original comment by trumb...@gmail.com on 15 Feb 2012 at 2:16

GoogleCodeExporter commented 8 years ago
in progress

Original comment by leonardo...@gmail.com on 16 Feb 2012 at 12:38

GoogleCodeExporter commented 8 years ago
This will be available in the next 3.2 JAR version. Obviously code has been 
committed and unit test written. thanks a lot for your contribution.

Original comment by leonardo...@gmail.com on 16 Feb 2012 at 1:22

GoogleCodeExporter commented 8 years ago

Original comment by leonardo...@gmail.com on 16 Feb 2012 at 10:43