B4A Library ABExtDrawing 1.0

alwaysbusy

Expert
Licensed User
Longtime User
Yes, I'm reading on the net that it is still a problem and SetLinearText does not fix this in 5 anymore. Seems the only workaround for the moment is scaling up:

In java it's solved like this:

final float magnifier = 100f;

// Scale the canvas
canvas.save();
canvas.scale(1f / magnifier, 1f / magnifier);

// increase the font size
mDegreeMarkingsPaint.setTextSize(originalTextSize * magnifier);

canvas.drawText(value, x*magnifier, y*magnifier,mDegreeMarkingsPaint);

//canvas.drawTextOnPath(value, textPath, 0.0f, 0.0f, mDegreeMarkingsPaint);

// bring everything back to normal
canvas.restore();

Should be possible with the existing lib.
 

HugoSX2

Member
Licensed User
Longtime User
Thank you, but I have no idea how to convert this java code into b4a.

Any help?
 

alwaysbusy

Expert
Licensed User
Longtime User
I'm not currently working in B4A (other project, other language) but it should be something like this:

Dim magnifier As Double = 100
Dim OriginalTextSize As Double = 20

myExDraw.save(tmpCanv)
myExDraw.scale(tmpCanv, 1/magnifier, 1/magnifier)

' hovever the paint is build
Dim mDegreeMarkingsPaint As ABPaint
mDegreeMarkingsPaint.Initialize
mDegreeMarkingsPaint.setDither(True)
mDegreeMarkingsPaint.setAntiAlias(True)
mDegreeMarkingsPaint.SetTextSize(OriginalTextSize * magnifier)

myExDraw.drawText(tmpCanv, "mytext", x * magnifier, y * magnifier, mDegreeMarkingsPaint)

myExDraw.restore(tmpCanv)
 

peacemaker

Expert
Licensed User
Longtime User
Hi,
Please, suggest a sub how to get 16 x 16 pixels Bitmap from any size source Bitmap.
Stratching for getting a picture hash.


I have found sub to get it https://www.b4x.com/android/forum/threads/wish-createscaledbitmap-core-function.21439/#content, but
B4X:
Sub GrayScale(bmp As Bitmap) As Bitmap
    Dim bmpGrayscale As Bitmap
    'bmpGrayscale.InitializeMutable(bmp.Width, bmp.height)
    bmpGrayscale.InitializeMutable(16dip, 16dip)
    Dim c As Canvas
    c.Initialize2(bmpGrayscale)

    Dim paint As ABPaint
    paint.Initialize

    Dim mat As ABColorMatrix
    mat.Initialize
    mat.SetSaturation(0)

    paint.SetColorMatrixColorFilter2(mat)
    Dim ExDraw As ABExtDrawing
    ExDraw.drawBitmap2(c, bmp, 0, 0, paint)
    Return bmpGrayscale
End Sub
drawBitmap2 is declared to scale the picture to the Canvas BMP that is 16 x 16 :-(
but not scaled into 16 x 16.
 
Last edited:

alwaysbusy

Expert
Licensed User
Longtime User
I don't think DrawBitmap2 scales the dimensions, only the density.

To scale you can use DrawBitmap4 with a matrix. Maybe it has to be done in two steps (first grayscale, then scale)

Something in the lines of (not tested):

B4X:
Dim bmpGrayscale As Bitmap
bmpGrayscale.InitializeMutable(16dip, 16dip)
Dim c As Canvas
c.Initialize2(bmpGrayscale)

Dim paint As ABPaint
paint.Initialize
paint.setDither(True)
paint.setAntiAlias(True)
paint.setFilterBitmap(True)

Dim mat As ABColorMatrix
mat.Initialize
mat.SetSaturation(0)
paint.SetColorMatrixColorFilter2(mat)

Dim innerScale As Float
innerScale = bmpGrayscale.width/bmp.width
Dim matrix As ABMatrix
matrix.postScale(innerScale, innerScale)

Dim ExDraw AsABExtDrawing
exDraw.drawBitmap4(c, bmp, matrix, paint)  

Return bmpGrayscale
 

TheMightySwe

Active Member
Licensed User
Longtime User
Hi, all,

has anyone made any cool resizeable buttons using this libray and feel like share some code??
 

Troberg

Well-Known Member
Licensed User
Longtime User
Really nice lib, although a bit overwhelming in its powerfulness.

I have a very distinct problem, and I can't find the apropriate methods to do it. My problem:

I have to bitmaps, one is an icon with an alpha channel (actually, the only thing I'm interested in is the alpha channel), the other is a background color/gradient. I want to combine these, so that I get an icon with the same transparency as the icon, but all the nontransparent pixels are replaced by the corresponding pixels from the other bitmap. In other words, the alpha channel works as a cookie cutter on the color bitmap.

To do this, I plan to use Porter-Duff modes, using:

Source: The color bitmap
Dest: The alpha icon
Porter-Duff mode: In

Now, I can find constants for PorterDuffMode in ABExtDrawing, but I can't find the right method to apply them.

I want to achieve something like (conceptually only, just to clarify, not exactly):

B4X:
Dim ABExtDraw as ABExtDrawing
BitmapResult=ABExtDraw.DrawPorterDuff(BitmapSource, BitmapDest, ABExtDraw.PorterDuffMode_IN)

How to do this?
 

alwaysbusy

Expert
Licensed User
Longtime User
Try this. (For some reason Drawbitmap2() does not work, so use DrawBitmap())

B4X:
Public Sub BuildBitmap(iPicture As Bitmap, iPicture2 As Bitmap) As Bitmap
   Dim exDraw As ABExtDrawing
   
   Dim xBuildPicture As Bitmap
   Dim xBuildCanvas As Canvas
     
   xBuildPicture.InitializeMutable(iPicture.Width, iPicture.Height)
   xBuildCanvas.Initialize2(xBuildPicture)
       
   Dim paint As ABPaint
   paint.Initialize
   paint.setDither(True)
   paint.setAntiAlias(True)
   paint.setFilterBitmap(True)   
   
   Dim d As Rect
   d.Initialize(0,0,iPicture.Width, iPicture.Height)
     
   exDraw.drawBitmap(xBuildCanvas, iPicture, Null, d, paint)
   
   paint.SetPorterDuffXfermode(paint.PorterDuffMode_SRC_IN)
   exDraw.drawBitmap(xBuildCanvas, iPicture2, Null, d, paint)
   
   Return xBuildPicture
End Sub
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
Do you know how I would make an image mask?
Ie: the alpha level of each pixel of a bitmap I draw I controlled by the shade of grey of a second bitmap. Black = 255, white = 0
 

Troberg

Well-Known Member
Licensed User
Longtime User
Found one minor hickup, and fixed it. The background and mask were swapped in the last few lines. Fixed code below, hope someone has use for it!

B4X:
Private Sub BuildBitmap(Back As Bitmap, Mask As Bitmap) As Bitmap
  Dim exDraw As ABExtDrawing
  Dim xBuildPicture As Bitmap
  Dim xBuildCanvas As Canvas

  xBuildPicture.InitializeMutable(Back.Width, Back.Height)
  xBuildCanvas.Initialize2(xBuildPicture)

  Dim paint As ABPaint
  paint.Initialize
  paint.setDither(True)
  paint.setAntiAlias(True)
  paint.setFilterBitmap(True)
 
  Dim d As Rect
  d.Initialize(0,0,Back.Width, Back.Height)
   
  exDraw.drawBitmap(xBuildCanvas, Mask, Null, d, paint)
  
  paint.SetPorterDuffXfermode(paint.PorterDuffMode_SRC_IN)
  exDraw.drawBitmap(xBuildCanvas, Back, Null, d, paint)
 
  Return xBuildPicture
End Sub

Once again, thanks for the help!
 

Elton Leung

Member
Licensed User
Longtime User
The 3Dcamera sample shows the possibility to create sudo 3d object with 2 transforming trapezoid shape bitmaps, I am impressed. I just wonder is the ABExtDrawing library can also transform triangle shape bitmap or shape with 4 sides. I like to create a warping effect similar to below picture. I know Pixel by Pixel plotting is possible, but it will be very slow.

I need a function that can change a square bitmap into any shape with the input of just 4 corners.

 

wirog80

Member
Licensed User
nice library for AB3DCamera..
can i change the image or text tittle at run time?
 

sultan87

Active Member
Licensed User
Longtime User
hello,
very nice
I created an app to manage a thermostat via SIM card
I took your abex drawing demo
but it does not show me the full figures as your example
how to position the needle on a precise value
values are in degrees Celsius or Fahrenheit
best regards
 

sultan87

Active Member
Licensed User
Longtime User
hello,
very nice
I created an app to manage a thermostat via SIM card
I took your abex drawing demo
how to position the needle on a precise value
best regards
 

Turbo3

Active Member
Licensed User
Longtime User
Any chance of getting the example code in the first post updated to work on Android 5.x by updating it with the code fragments in post #44?

It is not clear to me how you integrate the lines in post #44 into the example code. Has anyone done it and gotten it to display the all the scale digits rather than only the last digit?

Or is there a better way to get this working on Android 5?
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
How do I use path operations like RegionOp_DIFFERENCE? ie: I'd like to use it to subtract an oval path from a rect path
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
I'm using drawpoly to draw parts of an image distorted, but for some reason it draws the entire image instead of the part I defined as the source. Is there a way to limit it to just the source dimensions so I don't have to use a clippath?
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
Now I need RegionOp_INTERSECT.

B4X:
Sub OpPath(Path1 As Path, Path2 As Path, Op As Int) As Path
   Dim Operation As String
   Select Case Op
     Case -1:    Operation = "DIFFERENCE"
     Case 0:    Operation = "INTERSECT"
     Case 1:    Operation = "REVERSE_DIFFERENCE"     
     Case 2:    Operation = "UNION"'merge 2 paths together
     Case 3:    Operation = "XOR"
   End Select
  Dim jo As JavaObject = Path1, success As Boolean = jo.RunMethod("op", Array(Path2, Operation))
   Return Path1   
End Sub

This does 2 normal paths, but one of the paths I need are a handpath, and it won't work with this code
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…