Adding panels to canvas

artiechappie

Member
Licensed User
Longtime User
Hi Guys,

I am creating, as a small test project - an app which allows a user to design signs, nameplates etc. I am looking to create a canvas (or several canvases if needed) as a basis for this. In order to be able to use a "drag and drop" feature it looks as though I need to create several transparent panels so that the user can drag the text into the position they want on the canvas - let's say, for arguments sake, we have 3 panels on top of the canvas.

OK, so the user has finished their design and the text lines are where they need to be on the panels. How do I get the 3 panel layers on to the canvas so that this can be saved as a graphic file?

All help much appreciated as I'm relatively new to B4A and I'm sure it will all drop into place eventually.

Fantastic tool guys - well done!!
 

klaus

Expert
Licensed User
Longtime User
When the positions are OK you must copy the bitmaps of the different additional layers to the bitmap of the main layer.
I'm not sure if you have understoud the canvas principle.
A canvas is just a drawing object. You need one for each graphic layer.
So if you have a main layer (panel with a background) and three addiltional layers (transparent panels) you'll need 4 cavases, one for each layer.

Best regards.
 
Upvote 0

artiechappie

Member
Licensed User
Longtime User
OK. Thanks Klaus. I'll make a start and see how it goes. I've got most of the other bits in place, it was just this issue that I was struggling with the concept. I'll go back to the docs in the first instance.

Thanks again - great forum for new starters for B4A.
 
Upvote 0

Cdymock

Member
Licensed User
Longtime User
Cannot see Objects on canvas

Hi,

This is probably a silly mistake, I am trying to create a series of layers over a bitmap, when the user touches the panel it adds a transparent panel and attaches a canvas then draws a symbol depending on what option is selected text color is set from the text color of the currently on toggle.

However I get no errors but never see the text.

Sub CarImage_Touch (Action As Int, X As Float, Y As Float) As Boolean 'Return True to consume the event
Dim t As Int
t=currentToggle.TextColor
If symbol<>"" Then

lc=lc+1
If lc<257 Then
CarPanel(lc).Initialize("CarPanel")

CarPanel(lc).Color=Colors.Transparent
CarImagePanel.AddView(CarPanel(lc),0,0,100%x,60%y)
CarCanvas(lc).Initialize(CarPanel(lc))
carRect(lc).Initialize(0,0,100%x,60%y)
CarCanvas(lc).DrawRect(carRect(lc),Colors.Transparent,True,0)
CarCanvas(lc).DrawText(symbol,X,Y,currentToggle.Typeface,100,currentToggle.TextColor,"CENTER")
Else
Msgbox("Maximum number of defects allowed is 256","Maximum Defects")

End If
Else
Msgbox("Please select a defect.","No Selection")
End If
End Sub
 
Upvote 0

Cdymock

Member
Licensed User
Longtime User
Error Log

Hi Klaus,

it seems to be an out of memory error;

Starting activity: Intent { flg=0x20000 cmp=clockworkit.prodriver/.carimage } from pid 7650
** Activity (viewschedule) Pause, UserClosed = false **
** Activity (carimage) Create, isFirst = true **
GC_CONCURRENT freed 534K, 44% free 3474K/6151K, external 1392K/1904K, paused 7ms+5ms
GC_CONCURRENT freed 449K, 42% free 3606K/6215K, external 1392K/1904K, paused 2ms+7ms
GC_EXTERNAL_ALLOC freed 254K, 45% free 3427K/6215K, external 1392K/1904K, paused 30ms
** Activity (carimage) Resume **
handle fade alpha 17
handle fade alpha 41
handle fade alpha 71
handle fade alpha 93
handle fade alpha 114
handle fade alpha 134
handle fade alpha 153
handle fade alpha 169
handle fade alpha 184
handle fade alpha 198
[DISP] purgatorizeLayer_l 0xc12fd8 4
Displayed clockworkit.prodriver/.carimage: +752ms
handle fade alpha 210
[DISP] remove 0xc12fd8 2
handle fade alpha 221
handle fade alpha 230
handle fade alpha 238
handle fade alpha 244
handle fade alpha 249
handle fade alpha 253
GC_EXTERNAL_ALLOC freed 20K, 45% free 3434K/6215K, external 2558K/3195K, paused 61ms
GC_EXTERNAL_ALLOC freed 3K, 45% free 3434K/6215K, external 3725K/4651K, paused 85ms
GC_EXTERNAL_ALLOC freed 8K, 45% free 3430K/6215K, external 6058K/6108K, paused 62ms
GC_EXTERNAL_ALLOC freed 2K, 45% free 3432K/6215K, external 8391K/9021K, paused 28ms
binderDied() at ObserverNode name fs_id
Process com.google.android.apps.plus (pid 6317) has died.
GC_EXTERNAL_ALLOC freed 2K, 45% free 3434K/6215K, external 10724K/11605K, paused 85ms
GC_EXTERNAL_ALLOC freed 2K, 45% free 3437K/6215K, external 13057K/13938K, paused 28ms
GC_EXTERNAL_ALLOC freed 2K, 45% free 3439K/6215K, external 15390K/16271K, paused 28ms
Process android.process.media (pid 7702) has died.
GC_EXTERNAL_ALLOC freed 2K, 45% free 3441K/6215K, external 17722K/18604K, paused 38ms
Process com.htc.recommend (pid 7631) has died.
Process com.google.android.partnersetup (pid 7719) has died.
GC_EXTERNAL_ALLOC freed 2K, 45% free 3443K/6215K, external 20055K/20937K, paused 29ms
GC_EXTERNAL_ALLOC freed 2K, 45% free 3446K/6215K, external 22388K/23270K, paused 28ms
GC_EXTERNAL_ALLOC freed 2K, 45% free 3448K/6215K, external 24721K/25603K, paused 28ms
GC_EXTERNAL_ALLOC freed 12K, 45% free 3438K/6215K, external 25888K/27936K, paused 31ms
1194480-byte external allocation too large for this process.
Out of memory: Heap Size=6215KB, Allocated=3438KB, Bitmap Size=25888KB, Limit=32768KB
Trim info: Footprint=6215KB, Allowed Footprint=6215KB, Trimmed=396KB
VM won't let us allocate 1194480 bytes
Clamp target GC heap from 32.708MB to 32.000MB
GC_FOR_MALLOC freed <1K, 45% free 3438K/6215K, external 25888K/27936K, paused 20ms
Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0x4001d648)
FATAL EXCEPTION: main
java.lang.OutOfMemoryError: bitmap size exceeds VM budget(Heap Size=6919KB, Allocated=3438KB, Bitmap Size=25888KB)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:695)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper.Initialize(CanvasWrapper.java:71)
at clockworkit.prodriver.carimage._carpanel_touch(carimage.java:376)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:113)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:101)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:97)
at anywheresoftware.b4a.objects.PanelWrapper$1.onTouch(PanelWrapper.java:41)
at android.view.View.dispatchTouchEvent(View.java:3928)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:955)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:906)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:906)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:906)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:906)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:906)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1784)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1157)
at android.app.Activity.dispatchTouchEvent(Activity.java:2228)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1759)
at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2340)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1980)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4293)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
at dalvik.system.NativeStart.main(Native Method)
Force finishing activity clockworkit.prodriver/.carimage
enable: get sensor name = MPL accel
handle : 4 en: 1, v07-Correct timerirq initial delay setting
mEnabled = 0x10
mpu3050_resume: Resuming to 0070
pid=260, uid=1000
disable: get sensor name = MPL accel
handle : 4 en: 0, v07-Correct timerirq initial delay setting
MLGetAKMComassStatus, gAKMCompassStatus = 0
mEnabled = 0x0
mpu3050_suspend: suspending sensors to 0000
mpu3050_suspend: Will resume next to 0070
Activity pause timeout for HistoryRecord{40bba638 clockworkit.prodriver/.carimage}
pid=260, uid=1000
freeMemory=889716736
OoO SMS Memory available. SMS_AVAILABLE_THRESHOLD == 524288
Posting Message again
Launch timeout has expired, giving up wake lock!
Activity idle timeout for HistoryRecord{40c692e0 clockworkit.prodriver/.viewschedule}
New lightsensor value:225, lcdValue:120
Application is not responding: Window{40ad6780 clockworkit.prodriver/clockworkit.prodriver.carimage paused=false}. 15148.7ms since event, 15010.2ms since wait started
Input event dispatching timed out sending to clockworkit.prodriver/clockworkit.prodriver.carimage
Dropping event because the pointer is not down.
Dropping event because the pointer is not down.
Sending signal. PID: 7650 SIG: 9
Process clockworkit.prodriver (pid 7650) has died.
WIN DEATH: Window{408e4d98 clockworkit.prodriver/clockworkit.prodriver.main paused=false}
WIN DEATH: Window{40be4a50 clockworkit.prodriver/clockworkit.prodriver.viewschedule paused=false}
[DISP] purgatorizeLayer_l 0x14a5a48 4
WIN DEATH: Window{40ad6780 clockworkit.prodriver/clockworkit.prodriver.carimage paused=false}
enable: get sensor name = MPL accel
handle : 4 en: 1, v07-Correct timerirq initial delay setting
mEnabled = 0x10
[DISP] remove 0x14a5a48 2
Start proc clockworkit.prodriver for activity clockworkit.prodriver/.main: pid=7771 uid=10123 gids={1015, 3003, 1006}
mpu3050_resume: Resuming to 0070
pid=260, uid=1000
disable: get sensor name = MPL accel
handle : 4 en: 0, v07-Correct timerirq initial delay setting
MLGetAKMComassStatus, gAKMCompassStatus = 0
mEnabled = 0x0
mpu3050_suspend: suspending sensors to 0000
mpu3050_suspend: Will resume next to 0070
pid=260, uid=1000
fail to set top app changed!
[DISP] purgatorizeLayer_l 0xbbe240 5
[DISP] remove 0xbbe240 2
com.htc.autotest.dlib.RecordEngine in loader dalvik.system.DexClassLoader@40528850
Previously focused view reported id 9 during save, but can't be found during restore.
Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@4097f0e0 (uid=10123 pid=7771)
Client not active, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40722260
handle fade alpha 238
handle fade alpha 219
handle fade alpha 190
handle fade alpha 167
handle fade alpha 146
handle fade alpha 107
handle fade alpha 90
handle fade alpha 254
handle fade alpha 60
handle fade alpha 247
handle fade alpha 48
handle fade alpha 241
handle fade alpha 36
Displayed clockworkit.prodriver/.main: +495ms
handle fade alpha 234
handle fade alpha 18
handle fade alpha 214
handle fade alpha 12
handle fade alpha 203
handle fade alpha 3
handle fade alpha 175
handle fade alpha 1
[DISP] purgatorizeLayer_l 0x14a5a48 5
[unregister] handle 0xb0d60 still locked (state=40000001)
handle fade alpha 159
Activity destroy timeout for HistoryRecord{40bba638 clockworkit.prodriver/.carimage}
handle fade alpha 118
[DISP] remove 0x14a5a48 2
handle fade alpha 101
handle fade alpha 78
handle fade alpha 55
handle fade alpha 30
handle fade alpha 2
GC_CONCURRENT freed 377K, 45% free 3121K/5639K, external 0K/0K, paused 2ms+2ms
** Activity (main) Create, isFirst = true **
GC_CONCURRENT freed 398K, 44% free 3251K/5767K, external 0K/0K, paused 3ms+4ms
dbopen(): path = /mnt/sdcard/Android/data/clockworkit.prodriver/files/Prodriver/Data/Data.db, flag = 6, file size = 5120
sqlite returned: error code = 0, msg = Recovered 7 frames from WAL file /mnt/sdcard/Android/data/clockworkit.prodriver/files/Prodriver/Data/Data.db-wal
dbopen(): path = /mnt/sdcard/Android/data/clockworkit.prodriver/files/Prodriver/Data/Data.db, mode: wal, disk free size: 1330 M, handle: 0x397c98
** Activity (main) Resume **
 
Upvote 0

Cdymock

Member
Licensed User
Longtime User
unfiltered log

Here is the unfiltered log.

** Activity (carimage) Create, isFirst = true **
GC_CONCURRENT freed 586K, 44% free 3483K/6215K, external 1392K/1904K, paused 1ms+3ms
GC_CONCURRENT freed 452K, 43% free 3588K/6215K, external 1392K/1904K, paused 2ms+3ms
GC_EXTERNAL_ALLOC freed 129K, 45% free 3458K/6215K, external 1392K/1904K, paused 29ms
** Activity (carimage) Resume **
handle fade alpha 15
handle fade alpha 41
handle fade alpha 65
handle fade alpha 88
handle fade alpha 109
handle fade alpha 130
handle fade alpha 148
handle fade alpha 165
handle fade alpha 182
handle fade alpha 195
[DISP] purgatorizeLayer_l 0x701740 4
Displayed clockworkit.prodriver/.carimage: +703ms
handle fade alpha 208
[DISP] remove 0x701740 2
handle fade alpha 219
handle fade alpha 228
handle fade alpha 236
handle fade alpha 243
handle fade alpha 248
handle fade alpha 252
handle fade alpha 254
SendIntentforPowersaver
Current powersaver status == NORMAL_STATUS
[smart wifi] mSmartWiFiStatus: 0 mBatteryLevel: 33 mWifiConnected: true
[smart wifi] ACTION_BATTERY_CHANGED pluggedType: 2
GC_EXTERNAL_ALLOC freed 47K, 45% free 3441K/6215K, external 2558K/3195K, paused 77ms
GC_EXTERNAL_ALLOC freed 3K, 45% free 3441K/6215K, external 3725K/4651K, paused 74ms
GC_EXTERNAL_ALLOC freed 7K, 45% free 3439K/6215K, external 6058K/6108K, paused 88ms
GC_EXTERNAL_ALLOC freed 2K, 45% free 3441K/6215K, external 8391K/9021K, paused 26ms
GC_EXTERNAL_ALLOC freed 2K, 45% free 3443K/6215K, external 10724K/11605K, paused 64ms
GC_EXTERNAL_ALLOC freed 2K, 45% free 3445K/6215K, external 13057K/13938K, paused 29ms
GC_EXTERNAL_ALLOC freed 2K, 45% free 3448K/6215K, external 15390K/16271K, paused 32ms
GC_EXTERNAL_ALLOC freed 2K, 45% free 3450K/6215K, external 17722K/18604K, paused 27ms
GC_EXTERNAL_ALLOC freed 3K, 45% free 3452K/6215K, external 20055K/20937K, paused 90ms
GC_EXTERNAL_ALLOC freed 2K, 45% free 3454K/6215K, external 22388K/23270K, paused 27ms
GC_EXTERNAL_ALLOC freed 2K, 45% free 3457K/6215K, external 24721K/25603K, paused 27ms
GC_EXTERNAL_ALLOC freed 18K, 45% free 3441K/6215K, external 25888K/27936K, paused 27ms
1194480-byte external allocation too large for this process.
Out of memory: Heap Size=6215KB, Allocated=3441KB, Bitmap Size=25888KB, Limit=32768KB
Trim info: Footprint=6215KB, Allowed Footprint=6215KB, Trimmed=380KB
VM won't let us allocate 1194480 bytes
Clamp target GC heap from 32.709MB to 32.000MB
GC_FOR_MALLOC freed <1K, 45% free 3441K/6215K, external 25888K/27936K, paused 18ms
Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0x4001d648)
FATAL EXCEPTION: main
java.lang.OutOfMemoryError: bitmap size exceeds VM budget(Heap Size=6919KB, Allocated=3441KB, Bitmap Size=25888KB)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:695)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper.Initialize(CanvasWrapper.java:71)
at clockworkit.prodriver.carimage._carpanel_touch(carimage.java:376)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:113)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:101)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:97)
at anywheresoftware.b4a.objects.PanelWrapper$1.onTouch(PanelWrapper.java:41)
at android.view.View.dispatchTouchEvent(View.java:3928)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:955)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:906)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:906)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:906)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:906)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:906)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1784)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1157)
at android.app.Activity.dispatchTouchEvent(Activity.java:2228)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1759)
at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2340)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1980)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4293)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
at dalvik.system.NativeStart.main(Native Method)
Force finishing activity clockworkit.prodriver/.carimage
enable: get sensor name = MPL accel
handle : 4 en: 1, v07-Correct timerirq initial delay setting
mEnabled = 0x10
mpu3050_resume: Resuming to 0070
pid=260, uid=1000
Activity pause timeout for HistoryRecord{4098a230 clockworkit.prodriver/.carimage}
disable: get sensor name = MPL accel
handle : 4 en: 0, v07-Correct timerirq initial delay setting
MLGetAKMComassStatus, gAKMCompassStatus = 0
mEnabled = 0x0
mpu3050_suspend: suspending sensors to 0000
mpu3050_suspend: Will resume next to 0070
pid=260, uid=1000
[DISP] removeAbnormalLayer
GC_CONCURRENT freed 379K, 50% free 3156K/6279K, external 0K/0K, paused 5ms+10ms
Launch timeout has expired, giving up wake lock!
Activity idle timeout for HistoryRecord{408e3da8 clockworkit.prodriver/.viewschedule}
Application is not responding: Window{40df3980 clockworkit.prodriver/clockworkit.prodriver.carimage paused=false}. 15195.7ms since event, 15009.8ms since wait started
Dropping event because the pointer is not down.
Dropping event because the pointer is not down.
Input event dispatching timed out sending to clockworkit.prodriver/clockworkit.prodriver.carimage
Activity destroy timeout for HistoryRecord{4098a230 clockworkit.prodriver/.carimage}
 
Upvote 0

Cdymock

Member
Licensed User
Longtime User
Re Error

hi Klaus,

I am guessing that if I make the rectangles smaller for the layers this will reduce the size of the image?
 
Upvote 0

Cdymock

Member
Licensed User
Longtime User
Re Error

Hi,

I have tried to make the rectangles smaller but I can still only add 4 characters before I get a force close due to memory.

Is there anything else I can do?

Or Have I missed something in the error logs?

Appreciate the help.

Scratch that make panels smaller therefore canvas smaller, image smaller no error.

Cheers

Chris
 
Last edited:
Upvote 0
Top