B4A Library ABExtDrawing 1.0

ABExtDrawing 1.7

ABExtDrawing is a wrapper around the Android Drawing classes.

14/08/2012: Updated to version 1.7

Bugfixes and additional functions for blurring and masks.

16/02/2012: Updated to version 1.1

It makes it possible to access all the drawing functions of the Canvas. It is like the B4A canvas, but you can also use all Paints.

Several sub objects are also included:
ABPaint: a wrapper for thePaint class
ABMatrix: a wrapper for the Matrix class
ABRegion: a wrapper for the Region class
ABColorMatrix: a wrapper for the ColorMatrix class
ABCamera: a wrapper for the Camera class [NEW version 1.1]
ABRgbFunctions: several functions to manipulate RGB values

Also two extended classes
ABRectF: a wrapper around the RectF class. B4A contains the Rect class, but to use some of the functions of this library I needed the float version of Rect.
ABPath: a full wrapper for the Path class. B4A contains the Path class but only exposes LineTo. ABPath exposes all functions (like addArc, addOval, etc...)

This lib is to big to list all functions, but a lot of them are used in the attached demo. It is a B4A translation of the Thermometer project on Mind The Robot

Therm.png


How to use this library:

The main object is ABExtDrawing. You pass the B4A canvas to each function:
B4X:
Sub Globals
        Dim ExDraw As ABExtDrawing
        Dim MyCanvas As Canvas
        Dim Panel1 as Panel
end Sub

Sub Activity_Create(FirstTime As Boolean)
        If FirstTime Then
      Activity.LoadLayout("2")
      MyCanvas.Initialize(Panel1)   
   End If
        drawRim(MyCanvas)
End Sub

Sub drawRim(Canv As Canvas)
   ' first, draw the metallic body
   ExDraw.drawOval(Canv, rimRect, rimPaint)
   ' now the outer rim circle
   ExDraw.drawOval(Canv, rimRect, rimCirclePaint)
End Sub

The fun part is you can create all kind of Paints:
B4X:
        ' the linear gradient Is a Bit skewed For realism
   rimPaint.Initialize
   rimPaint.SetFlags(rimPaint.flag_ANTI_ALIAS_FLAG)
   rimPaint.SetLinearGradient2(1,0.40, 0.0, 0.60, 1.0, Colors.RGB(0xf0, 0xf5, 0xf0),Colors.RGB(0x30, 0x31, 0x30),rimPaint.ShaderTileMode_CLAMP)   
   rimPaint.DoShaderSingle(1)

   rimCirclePaint.Initialize
   rimCirclePaint.SetAntiAlias(True)
   rimCirclePaint.SetStyle(rimCirclePaint.Style_STROKE)
   rimCirclePaint.SetColor(Colors.ARGB(0x4f, 0x33, 0x36, 0x33))
   rimCirclePaint.SetStrokeWidth(0.005)

or make extended Paths:
B4X:
        handPath.Initialize
   handPath.moveTo(0.5, 0.5 + 0.2)
   handPath.lineTo(0.5 - 0.010, 0.5 + 0.2 - 0.007)
   handPath.lineTo(0.5 - 0.002, 0.5 - 0.32)
   handPath.lineTo(0.5 + 0.002, 0.5 - 0.32)
   handPath.lineTo(0.5 + 0.010, 0.5 + 0.2 - 0.007)
   handPath.lineTo(0.5, 0.5 + 0.2)
   handPath.addCircle(0.5, 0.5, 0.025, handPath.Direction_CW)

You can also use the Save and Restore functions of the canvas:
B4X:
Sub drawScale(Canv As Canvas)
   ExDraw.drawOval(Canv, scaleRect, ScalePaint)

   ExDraw.save2(Canv, ExDraw.MATRIX_SAVE_FLAG)
   Dim i As Int
   Dim y1 As Float
   Dim y2 As Float
   Dim value As Int
   Dim valueString As String
   For i = 0 To totalNicks
      y1 = scaleRect.top
      y2 = y1 - 0.020
         
      ExDraw.drawLine(Canv, 0.5, y1, 0.5, y2, ScalePaint)
         
      If (i Mod 5 = 0) Then
         value = nickToDegree(i)
         If (value >= minDegrees AND value <= maxDegrees) Then
            valueString = value
            ExDraw.drawText(Canv, valueString, 0.5, y2 - 0.015, ScalePaint)
         End If
      End If
         
      ExDraw.rotate2(Canv, degreesPerNick, 0.5, 0.5)
   Next
   ExDraw.restore(Canv)
End Sub

For more information on what is possible, look into the Android documentation

There is a new article on the Camera class (see the AB3DCamera project) that shows you how to make a 3D list with ABExtDrawing 1.1. The article can be found at Alwaysbusy's Corner. The project is also attached to this post.

3DCamera.png
 

Attachments

  • ABExtDrawing - Demo.zip
    168 KB · Views: 3,025
  • AB3DCamera.zip
    265.4 KB · Views: 2,350
  • ABExtDrawing 1.7.zip
    51.6 KB · Views: 3,127
Last edited:

francoisg

Active Member
Licensed User
Longtime User
Drop shadows

Hi,
is there any easy way of generating drop shadows? I have many images (transparent .png images) that I need to dynamically generate shadows for (images are loaded from a server and can change in the future, so using something like Photoshop to change the images would not work!) ...

Any help would be appreciated!
 

MrKim

Well-Known Member
Licensed User
Longtime User
When I try to run ABMeter.b4a it loads a blank screen. The following is the log when it loads.

Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.ab.abmeter/.main }
Start proc com.ab.abmeter for activity com.ab.abmeter/.main: pid=472 uid=10039 gids={}
Could not find method android.graphics.Canvas.isHardwareAccelerated, referenced from method com.AB.ABExtDrawing.ABExtDrawing.isHardwareAccelerated
VFY: unable to resolve virtual method 226: Landroid/graphics/Canvas;.isHardwareAccelerated ()Z
VFY: replacing opcode 0x6e at 0x0002
VFY: dead code 0x0005-0006 in Lcom/AB/ABExtDrawing/ABExtDrawing;.isHardwareAccelerated (Lanywheresoftware/b4a/objects/drawable/CanvasWrapper;)Z
** Activity (main) Create, isFirst = true **
GC_EXTERNAL_ALLOC freed 4766 objects / 259256 bytes in 88ms
GC_EXTERNAL_ALLOC freed 817 objects / 42144 bytes in 78ms
** Activity (main) Resume **
fdhandler_accept_event: accepting on fd 10
created client 0x17fe8 listening on fd 15
client_fd_receive: attempting registration for service 'sensors'
client_fd_receive: -> received channel id 27
Launch timeout has expired, giving up wake lock!
Activity idle timeout for HistoryRecord{4500ac28 com.ab.abmeter/.main}
request time failed: java.net.SocketException: Address family not supported by protocol

I am using an Android 2.2 emulator API Level 8
I get the same results with Google APIs 2.2 API Level 8

I then have to force the App closed.
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
I'm using mMatrix.setPolyToPoly and ExDraw.drawBitmap4 to draw part of a bitmap as a trapezoid using a SRC rect. The problem is, it's drawing the entire bitmap around that SRC instead of just what's inside it. How do I change that?

I'm working around it with a path, but I'd prefer not to since you can only use 1 at a time.
 

danijel

Active Member
Licensed User
Longtime User
Can someone help me just draw picture on Canvas using this library?
I need to avoid canvas using Nearest neighbor and I need to use Bicubic resample image.
I trying without success.

Basicly i need only this but with Bicubic resample image:
B4X:
Sub Globals
    Dim Canvas1 As Canvas
    Dim Logo As Bitmap
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Logo.Initialize(File.DirAssets,"logo.png")
    Dim SrcRect As Rect
    SrcRect.Initialize(0,0,1080, 1920)
    Dim DestRect As Rect
    DestRect.Initialize(0,0,540, 960)
    Canvas1.Initialize(Activity)
    Canvas1.DrawBitmap(Logo,SrcRect,DestRect)
End Sub
I will be very grateful
 
Last edited:

GMan

Well-Known Member
Licensed User
Longtime User
Where i can find the 3D Camera Project thread ?
I want to add an background image behind the turning 3d "cubes"
 

GMan

Well-Known Member
Licensed User
Longtime User
And how can i get/identify a clicked "cube" ?
 

asales

Expert
Licensed User
Longtime User
Great library!
It's possible to lock the scrolling when the picture reaches the bottom?
 

Attachments

  • SC20140921-114057.png
    SC20140921-114057.png
    20.9 KB · Views: 259

ibra939

Active Member
Licensed User
Longtime User
thank you
 
Top