These are the screenshots
Source:Flipped horizontally:Flipped vertically:
(Lower imageview is not used in this example)
And this is the code: (img1 is a b4xview)
B4X:
Dim iv As ImageView = Img1
Dim bmp As B4XBitmap = iv.Bitmap
Img1.SetBitmap(bmCEf.FlipHorizontal(bmp))
It is related to the bitmap scale and to the way you set the image to the ImageView.
There are several ways to solve it. One way:
B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private Btn1 As B4XView
Private Btn2 As B4XView
Private Btn3 As B4XView
Private Img1 As B4XView
Private Img2 As B4XView
Dim bmCEf As BitmapCreatorEffects
Private xui As XUI
End Sub
Sub Activity_Create(FirstTime As Boolean)
bmCEf.Initialize
Activity.LoadLayout("Ly0")
Btn3.Visible=False
fillImg1(Img1)
End Sub
Private Sub fillImg1(Img As B4XView)
Dim bc As BitmapCreator
bc.Initialize(Img.Width / xui.Scale, Img.Height / xui.Scale) '<-- disable the scale factor. This will improve performance.
Dim gpx As BCPath
gpx.Initialize(0,0)
gpx.LineTo(bc.mWidth/2, bc.mHeight/3)
gpx.LineTo(bc.mWidth/2,bc.mHeight)
gpx.LineTo(0,bc.mHeight)
gpx.LineTo(0,0)
bc.DrawPath(gpx,Colors.Red,True,0)
Img1.SetBitmap(bc.Bitmap)
End Sub
Sub Btn2_Click
Dim iv As ImageView = Img1
Dim bmp As B4XBitmap = iv.Bitmap
bmp=bmCEf.FlipVertical(bmp)
Img1.SetBitmap(bmp)
End Sub
Sub Btn1_Click
Dim iv As ImageView = Img1
Dim bmp As B4XBitmap = iv.Bitmap
Img1.SetBitmap(bmCEf.FlipHorizontal(bmp))
End Sub
Thank you Erel, another time!
so it seems that there are more differences as just Gravity between .setBitmap and .setBitmapToImageview than the intellisense tells me:
Hard to understand...
Do you somewhere have a tutorial, where I can understand the reason for that and get to know, why my case is not one of the 'most cases'.
I am not shure, if I may introduce the effect of fliphorizontally in my main-project in this thread or if I shall open a new one. I do it here, because I suppose it is all the same issue.
I set a figure in a label with a csbuilder (draws is a class, in original code another bmp is added too)
B4X:
Private Sub fillLblPicKanten
Dim bmp As B4XBitmap
Dim cs As CSBuilder
'not flipped
bmp=draws.drawGrindEdge(LblPicKanten.Width/2,LblPicKanten.Height,gv.LastAngle,2,0,False,False,True,True,True,False)
'flipped v ^
'bmp=draws.drawGrindEdge(LblPicKanten.Width/2,LblPicKanten.Height,gv.LastAngle,2,0,True,False,True,True,True,False)
cs.Initialize.Image(bmp,LblPicKanten.Width/2,LblPicKanten.Height,False).Popall
LblPicKanten.Text=cs
End Sub
I build this figure in a sub in class draws: (lots of code omitted)
B4X:
public Sub drawGrindEdge(picWidth As Float,picHeight As Float, grindAngle As Float, _
doAdjust As Int, rotAngle As Float, _
flipHoriz As Boolean, flipVertical As Boolean, highlightBevelUpper As Boolean, _
highlightBevelLower As Boolean,showHelpLines As Boolean, onebevel As Boolean) As B4XBitmap
Dim canv As B4XCanvas
Dim gpx As B4XPath
'...lots of code calculating the shape of path
Dim xview As B4XView = xui.CreatePanel("")
xview.SetLayoutAnimated(0, 0, 0, picWidth, picHeight)
'... lots of code, filling canvas
canv.Initialize(xview)
canv.DrawPath(gpx,Colors.Black,True,0)
canv.Invalidate
Dim bmp As B4XBitmap=canv.CreateBitmap
If flipHoriz Then
bmp=BmEf.FlipHorizontal(bmp) 'this flip changes quality of bmp
End If
Return bmp
End Sub
The original bmp looks pretty, the flipped one looks poor:
Is it possible for you, to tell why the flipped one looks so bad just from this rudimentary codelines?
Thank you for your effort, Erel!
The draw-routine is not yet ready - I am still struggling with this project. But the strange flip-effect is to be seen.
For performance reasons, BitmapCreatorEffects scales down the bitmap, you can prevent it with this code:
B4X:
If flipHoriz Then
bmp=bmEF.FlipHorizontal(ScaleBitmap(bmp))
End If
Return bmp
End Sub
Sub ScaleBitmap(bmp As B4XBitmap) As B4XBitmap
#if B4A
Dim jo As JavaObject = bmp
jo.RunMethod("setDensity", Array(160))
#End If
Return bmp
End Sub