-1

2 Graphics2D objects are being created with alphaComposite "embedded" in their creation process (so an additional setComposite in front seems useless) there is ability to export as SVGs in Batik SVGGenerator and JFreeSVG libraries and the vector export is perfect. I would like to create a new Graphics2D object that is a simple blend AlphaComposition of those and be able to export vectors as well. When creating bufferedimages for each by using setComposite() and drawImage() methods, the raster nature of the the final object handles this "global" alpha composite well and I use it as a preview.

original Graphics2D object 1 --> BufferedImage imageAexport original Graphics2D object 2 --> BufferedImage imageBexport

         BufferedImage imageSynthesisRasterExport = new BufferedImage(w,h,BufferedImage.TYPE_INT_ARGB);

Graphics2D  g2export = imageSynthesisRasterExport.createGraphics();

g2export.fillRect(0,0,imageSynthesisRasterExport.getWidth(),imageSynthesisRasterExport.getHeight());
g2export.setComposite(getCompositeSliderMain()); //LEVEL 1
g2export.drawImage(imageAexport, 0, 0, null);
g2export.setComposite(getCompositeSliderClone()); // LEVEL 2
g2export.drawImage(imageBexport, 0, 0, null);

... (sorry for not being able to have a ready to run example, hopefully I can explain it)

This "raster" way, the final alpha blended image can be exported as a PNG, but in Batik, obviously SVGGenerator creates a Base64 embedded raster, not vectors (I guess because of the drawImage() method translation). Is there an other way/example/trick to avoid usage of intermediate bufferedimages and instead, use directly original Graphics2D objects in order to gain the ability to "translate" to vector? An object "wrapping" maybe? thanks

jazznbass
  • 24
  • 6
  • An idea is to use Batik's direct DOM implementation and apply alphaComposite between 2 exported SVG files from the original Graphics2D objects and create a new one. But there could be other ways around. – jazznbass May 04 '23 at 12:33

1 Answers1

0

This issue has been solved using Batik's direct DOM implementation by merging exported SVGs and setting the opacity of each one to global group elements, only src_over is applicable, as other alphaComposite operators are related mostly to raster, Batik tries to emulate some of those with svg filters but results are not as expected, so as far as I can see the only useable and predictable way to overlay graphics is the src_over operator translated to svg overall group opacity or by changing rgb values on every element.

<svg>
  <g opacity="0.5">

  </g>
</svg>
jazznbass
  • 24
  • 6