<noob>Trying to combine SVG lib and Card Shell

kcorey

Member
Licensed User
Longtime User
Hi All.

:sign0104:

I'm trying to combine the card shell and the SVG library. Should be easy, right?

I'm doing something silly here and getting 19 black squares. Can anyone point out where I'm going wrong?

In the designer I've got 19 ImageViews called "C0", "C1", ...

Because the ImageViews are in the designer, I don't need to Initialize or Activity.AddView, right?

By the end of initcards I /should/, I think, have 19 cards showing on the screen, but somehow the SVG isn't drawing onto my canvas, or my canvas isn't showing the "correct" bitmap.

My code is below.

-Ken

P.S. this started out feeling like a short post, but after adding code and the source code of one of the SVG it now feels too long. Is it usually better practice to just .zip up the whole project and put a link to that here?

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

   Dim C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14, C15, C16, C17, C18 As ImageView
   Dim CardViews() As ImageView
   Dim cardpics(19) As Bitmap
   Dim canvases(19) As Canvas
         
End Sub

Sub initcards
   Dim svgfiles() As String
   svgfiles = Array As String("MB-100.svg", "MB-200.svg", "MB-25.svg", "MB-50.svg", "MB-75.svg", "MB-ace.svg", "MB-crash.svg", "MB-emergency.svg", "MB-empty.svg", "MB-flat.svg", "MB-gas.svg", "MB-limit.svg", "MB-repair.svg", "MB-roll.svg", "MB-sealant.svg", "MB-spare.svg", "MB-stop.svg", "MB-tanker.svg", "MB-unlimited.svg")
   CardViews = Array As ImageView(C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14, C15, C16, C17, C18)
   
   Dim rect1 As Rect
   rect1.Initialize(0, 0, 40, 70)

   For i=0 To 18
      ' Make a Bitmap in which to draw
      cardpics(i).InitializeMutable(40,70)

      ' Create a new SVG object (necessary each time?)
      Dim SVG As SVG
      SVG.Initialize(File.DirAssets, svgfiles(i))

      ' Set up the canvas to draw into the bitmap
      canvases(i).Initialize2(cardpics(i))
      canvases(i).DrawRect(rect1,Colors.Green,True,0.0)
      
      SVG.DrawPicture(canvases(i), rect1)
      CardViews(i).Tag = i
      CardViews(i).Bitmap = cardpics(i)
      CardViews(i).Height = cardpics(i).Height
      CardViews(i).Width = cardpics(i).Width
   Next
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Dim SVG As SVG
   Activity.LoadLayout("homescreen")
   
   If FirstTime Then
      initcards
      Activity.Invalidate
   End If
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
---------------------------------------------------------------------
MB-25.svg
B4X:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="192" height="264" version="1.1" xmlns="http://www.w3.org/2000/svg">

<!-- black-bordered card background -->
<rect x="5" y="5" rx="11" ry="11" width="182" height="254"
style="fill: rgb(255,255,255);
stroke-width: 2;
stroke: rgb(0,0,0)" />

<!-- green-bordered milestone -->
<path d="M 29 220
H 162
V 80
C 136.60085,31.645824 58.999863,30.168114 29,80
Z"
style="fill: rgb(255,255,255);
stroke-width: 5;
stroke: rgb(24,117,52)" />

<!-- red 2 -->
<path d="M 57.566416,124.76415 L 57.449411,110.95758 C 62.16069,107.00891 69.052749,105.67718 76.872226,105.45835 C 93.688455,106.27477 94.554882,113.47112 94.539968,121.02 C 95.403214,141.78959 71.925347,135.99803 72.075025,146.76108 C 75.778979,146.71585 79.766716,146.98988 78.6273,141.49586 L 93.603929,141.72987 L 93.486924,157.52553 L 56.513372,157.52553 L 56.630377,142.5489 C 57.561281,127.9862 80.815191,127.60159 78.510295,120.66898 C 78.884616,117.47988 77.587745,117.00777 75.819182,116.57381 C 70.936171,117.60122 73.514185,121.82622 72.543045,124.53015 L 57.566416,124.76415 Z"
style="fill: rgb(239,31,29)" />

<!-- red 5 -->
<path d="M 98.480416,106.62443 L 134.44508,106.62443 L 134.44508,120.38273 L 119.47992,120.46318 C 118.6301,116.44611 115.85883,117.23268 113.36512,117.32533 L 113.44558,123.60104 C 131.66124,118.14821 135.65355,129.10005 135.57149,139.93399 C 136.0421,154.25373 128.16779,158.14231 117.54893,158.60021 C 109.55559,158.49786 103.25565,156.47632 98.480416,152.72678 L 98.399959,138.48574 L 113.60649,138.48574 C 113.3687,143.2196 113.58574,146.94857 116.42252,147.49702 C 118.45792,147.25184 119.40694,146.73248 119.64083,140.0949 C 119.42847,134.98559 118.3286,132.24295 116.48491,132.453 C 115.09615,132.61122 113.74133,133.14882 113.6065,134.62377 L 98.480416,134.46285 L 98.480416,106.62443 Z"
style="fill: rgb(239,31,29)" />

</svg>
 

kcorey

Member
Licensed User
Longtime User
Hi All.

:sign0104:

I'm trying to combine the card shell and the SVG library. Should be easy, right?

Turns out that the SVG library doesn't support the .svg files I was trying to use. They just get colored black for some reason.

Nevermind...:eek:

-Ken
 
Upvote 0
Top