B4A Library ABExtDrawing 1.0

Discussion in 'Additional libraries, classes and official updates' started by alwaysbusy, Feb 3, 2012.

  1. HugoSX2

    HugoSX2 Member Licensed User

  2. alwaysbusy

    alwaysbusy Expert Licensed 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.
     
  3. HugoSX2

    HugoSX2 Member Licensed User

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

    Any help?
     
  4. alwaysbusy

    alwaysbusy Expert Licensed 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)
     
  5. peacemaker

    peacemaker Well-Known Member Licensed 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 http://www.b4x.com/android/forum/threads/wish-createscaledbitmap-core-function.21439/#content, but
    Code:
    Sub GrayScale(bmp As BitmapAs Bitmap
        
    Dim bmpGrayscale As Bitmap
        
    'bmpGrayscale.InitializeMutable(bmp.Width, bmp.height)
        bmpGrayscale.InitializeMutable(16dip16dip)
        
    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, 
    00paint)
        
    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: Mar 19, 2015
  6. alwaysbusy

    alwaysbusy Expert Licensed 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):

    Code:
    Dim bmpGrayscale As Bitmap
    bmpGrayscale.InitializeMutable(
    16dip16dip)
    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, 
    matrixpaint)  

    Return bmpGrayscale
     
    peacemaker likes this.
  7. peacemaker

    peacemaker Well-Known Member Licensed User

    Thanks! Possible to get black & white bitmap ? Maximally grey-scaled :)
     
  8. TheMightySwe

    TheMightySwe Active Member Licensed User

    Hi, all,

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

    Troberg Well-Known Member Licensed 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):

    Code:
    Dim ABExtDraw as ABExtDrawing
    BitmapResult=ABExtDraw.DrawPorterDuff(BitmapSource, BitmapDest, ABExtDraw.PorterDuffMode_IN)
    How to do this?
     
  10. alwaysbusy

    alwaysbusy Expert Licensed User

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

    Code:
    Public Sub BuildBitmap(iPicture As Bitmap, iPicture2 As BitmapAs 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
     
    Pooya1 and Troberg like this.
  11. NeoTechni

    NeoTechni Well-Known Member Licensed 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
     
  12. Troberg

    Troberg Well-Known Member Licensed 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!

    Code:
    Private Sub BuildBitmap(Back As Bitmap, Mask As BitmapAs 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!
     
  13. Elton Leung

    Elton Leung Member Licensed 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.

    [​IMG]
     
  14. wirog80

    wirog80 Member Licensed User

    nice library for AB3DCamera..
    can i change the image or text tittle at run time?
     
  15. sultan87

    sultan87 Active Member Licensed 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
     
  16. sultan87

    sultan87 Active Member Licensed 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
     
  17. Turbo3

    Turbo3 Active Member Licensed 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?
     
  18. NeoTechni

    NeoTechni Well-Known Member Licensed 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
     
  19. NeoTechni

    NeoTechni Well-Known Member Licensed 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?
     
  20. NeoTechni

    NeoTechni Well-Known Member Licensed User

    Now I need RegionOp_INTERSECT.

    Code:
    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
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice