KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Specify SVG Embedded Image area span with transparency
PRODUCT: 4D | VERSION: 14.0 | PLATFORM: Mac & Win
Published On: November 26, 2014

When using the command SVG_New_embedded_image to add an image as an SVG object into an SVG document, its area span on a coordinate plane will be any location that is not transparent. As shown in the examples below.

With a image that doesn't have any transparencies any coordinate within the Height and Width of the image is part of the SVG object as shown:


If there are transparent parts to the image 4D will not consider these parts are existent in the SVG object as seen below where the center of the circle is transparent:


The SVG object only exists in coordinates where a pixel of image(color) exists as seen below where the mouce hovers the circle:


Taking advantage of the new Transparent function of v14R3 and this property of SVG objects when adding an embedded image can be useful in using images in a more accurate manner.

Extras:

Code used to generate SVG Document:

C_TEXT($svgRef;$path)
ARRAY TEXT($objRef;2)
C_PICTURE($pic)

$svgRef:=SVG_New

$path:=(Get 4D folder(Current resources folder)+"CircleWhiteBG.png")
READ PICTURE FILE($path;$pic)
If (OK = 1)
 TRANSFORM PICTURE($pic;Scale;3;3)
 $objRef{1}:=SVG_New_embedded_image ($svgRef;$pic;10;10)
 SVG_SET_ID ($objRef{1};"White BG")
End if

$path:=(Get 4D folder(Current resources folder)+"CircleTransBG.png")
READ PICTURE FILE($path;$pic)
If (OK = 1)
 TRANSFORM PICTURE($pic;Scale;3;3)
 $objRef{2}:=SVG_New_embedded_image ($svgRef;$pic;10;110)
 SVG_SET_ID ($objRef{2};"Trans BG")
End if

SVG EXPORT TO PICTURE($svgRef;pictObj;Copy XML data source)


Code used to display SVG Object's ID in Variable Object which is placed in the picture object's (pictObj) object method:
Case of
 : (Form event=On Mouse Move)
  GET MOUSE($MouseX;$MouseY;$MouseButton)
  $varObj:=SVG Find element ID by coordinates(*;"pictObj";$MouseX;$MouseY)
End Case