iOS Question Picture overlay edge transparent

cxbs

Member
Licensed User
Hello everyone!
I encountered a problem when using bitmapcreator to draw cloth embroidery effect picture,
How to remove the edge color after line superposition,
thank you!
The above English is from translation software

line.jpg


B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private xui As XUI
    Private ImageView1 As ImageView
    Private mBcLine As BitmapCreator
    Private mLineWidth As Int
    Private mLineHeigth As Int
    
    Private Button1 As Button
End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.RootPanel.LoadLayout("Page1")
    NavControl.ShowPage(Page1)
    
    mBcLine = BitmapToBC(LoadBitmap(File.DirAssets,"Line5.png"), 1)
    mLineWidth=mBcLine.mWidth
    mLineHeigth=mBcLine.mHeight
    ImageView1.Color=Colors.Green
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
    ImageView1.SetLayoutAnimated(0,0,0,ImageView1.Top,Width,Height-ImageView1.Top)
End Sub

Sub Button1_Click
    'xui.MsgboxAsync("Hello world!", "B4X")
    Dim Task As DrawTask
    Task=getDrawTask(Colors.RGB(255,127,39),mLineWidth*1.5,mLineHeigth*1.5)
    Dim bc As BitmapCreator
    Dim w As Int=ImageView1.Width
    Dim h As Int=ImageView1.Height
    Dim l As Int=Task.SrcRect.Right
    Dim x As Int,y As Int
    bc.Initialize(w,h)
    For i=1 To 50
        x=Rnd(0,w)
        y=Rnd(0,h)
        Task.TargetX=x
        Task.TargetY=y
        Task.Degrees=Rnd(0,360)
        Task.SrcRect.Right=Rnd(mLineWidth,l)
        bc.DrawBitmapCreatorTransformed(Task)
    Next
    bc.SetBitmapToImageView(bc.Bitmap,ImageView1)   
End Sub

Private Sub getDrawTask(mColor As Int,w As Int,h As Int) As DrawTask
    Dim bc2 As BitmapCreator
    bc2=GreyscaleToColor(mBcLine,mColor)
    Dim mBmp As Bitmap=bc2.Bitmap
    
    bc2.Initialize(w*20,h)
    bc2.DrawRect2(bc2.TargetRect,bc2.CreateBrushFromBitmap(mBmp.Resize(w,h,True)),True,h)
    
    Dim bc3 As BitmapCreator
    bc3.Initialize(w*20,h)
    bc3.DrawBitmap(bc2.Bitmap,bc2.TargetRect,True)
    
    Return bc3.CreateDrawTask(bc3,bc3.TargetRect,0,0,True)
End Sub


Private Sub CopyBC(bc As BitmapCreator,SkipBlending As Boolean) As BitmapCreator
    Dim b2 As BitmapCreator
    b2.Initialize(bc.mWidth, bc.mHeight)
    b2.DrawBitmapCreator(bc, bc.TargetRect, 0, 0,  SkipBlending)
    Return b2
End Sub

Private Sub BitmapToBC(bmp As B4XBitmap, Scale As Float) As BitmapCreator
    Dim b2 As BitmapCreator
    b2.Initialize(bmp.Width / Scale, bmp.Height / Scale)
    b2.CopyPixelsFromBitmap(bmp)
    Return b2
End Sub

Private Sub GreyscaleToColor (src As BitmapCreator, TargetColor As Int) As BitmapCreator
    Dim bc As BitmapCreator = CopyBC(src,True)
    Dim a As ARGBColor
    Dim clr As ARGBColor
    Dim t As PremultipliedColor
    
    src.ColorToARGB(TargetColor, clr)
    For y = 0 To src.mHeight - 1
        For x = 0 To src.mWidth - 1
            src.GetARGB(x, y, a)
            If a.r<>255 And a.g<>255 And a.b<>255 Then
                Dim f As Float = a.r / 255
                a.r = clr.r * f
                a.g = clr.g * f
                a.b = clr.b * f
                If a.r>226 Then
                    a.a=300-a.r
                End If
                bc.SetARGB(x, y, a)
            Else
                bc.SetPremultipliedColor(x,y,t)
            End If
        Next
    Next
    Return bc
End Sub
 

Attachments

  • CompositeTransparent.zip
    5.3 KB · Views: 8

cxbs

Member
Licensed User
As I've already wrote in another question of yours, it is easier to develop such algorithms in B4J. If you want me to help you then create a B4XPages project that works in B4i and B4J and upload it.
Dear Mr. Erel, Hello!
I uploaded a small example supporting b4j and b4i,
Thank you very much for your help!
 

Attachments

  • CompositeTransparent2.zip
    12.1 KB · Views: 9
Upvote 0

cxbs

Member
Licensed User
Very bad:
B4X:
    #if B4j
        ImageView1.SetLayoutAnimated(0,0,ImageView1.Top,Root.Width,Root.Height-ImageView1.Top)
    #else if B4i
        ImageView1.SetLayoutAnimated(0,0,0,ImageView1.Top,Root.Width,Root.Height-ImageView1.Top)
    #end if
Very good: change its type to B4XView.

Add:
B4X:
Task.SkipBlending = False

Dear Mr. Erel
You're right. I've read your article,
But I didn't notice that this parameter has such a big effect,
Thank you very much for your help!
 
Upvote 0
Top