Sub Crop_Image(V As B4XView, left As Int, top As Int, width As Int, height As Int) As Bitmap
Dim Btm As Bitmap = V.Snapshot
Dim Canv As Canvas
Dim MyBitmap As Bitmap
MyBitmap.InitializeMutable(width,height)
Canv.Initialize2(MyBitmap)
Dim R As Rect
R.Initialize(left,top,width,height)
Dim R2 As TextReader
R2.Initialize(0,0,width,height)
Canv.DrawBitmap(Btm,R,R2)
Return Canv.Bitmap
End Sub
if I wanted to do this kind of clipping?Try this:
B4X:Sub Crop_Image(V As B4XView, left As Int, top As Int, width As Int, height As Int) As Bitmap Dim Btm As Bitmap = V.Snapshot Dim Canv As Canvas Dim MyBitmap As Bitmap MyBitmap.InitializeMutable(width,height) Canv.Initialize2(MyBitmap) Dim R As Rect R.Initialize(left,top,width,height) Dim R2 As TextReader R2.Initialize(0,0,width,height) Canv.DrawBitmap(Btm,R,R2) Return Canv.Bitmap End Sub
This code imports the background image of the view and cuts the square indicated by the coordinates (left, top, width, height) and returns the resulting bitmap
if I wanted to do this kind of clipping?Why not:
B4X:Sub Crop_Image(V As B4XView, left As Int, top As Int, width As Int, height As Int) As Bitmap Return V.Snapshot.Crop(left, top, width, height) End Sub
pre-established shapes! can you make me an example directly? because I really can not do itUse the Path to select the part and cut out with canvas.
Is the figure cut out manually or do you have pre-established shapes?
I'm off-site I'm sorry I can not nowpre-established shapes! can you make me an example directly? because I really can not do it
I enclose the pre-established form
Sub ButtonCut_Click
Dim Canv As Canvas
Canv.Initialize(PanelMain)
Canv.DrawColor(Colors.Transparent)
Dim P As Path
P.Initialize(Point(0).X,Point(0).Y)
For i=1 To Point.Length-1
P.LineTo(Point(i).X,Point(i).Y)
Next
Canv.ClipPath(P)
Dim r As Rect
r.Initialize(0,0,PanelMain.Width,PanelMain.Height)
Canv.DrawBitmap(LoadBitmap(File.DirAssets,"cavallo_0.jpg"),Null,r)
End Sub
my problem is not the clipping with the fingers, but the cropping through a pre-set image as in the example I want to cut out only what is inside the t-shirtFirst example: Freehand image cropping.
View attachment 67180
B4X:Sub ButtonCut_Click Dim Canv As Canvas Canv.Initialize(PanelMain) Canv.DrawColor(Colors.Transparent) Dim P As Path P.Initialize(Point(0).X,Point(0).Y) For i=1 To Point.Length-1 P.LineTo(Point(i).X,Point(i).Y) Next Canv.ClipPath(P) Dim r As Rect r.Initialize(0,0,PanelMain.Width,PanelMain.Height) Canv.DrawBitmap(LoadBitmap(File.DirAssets,"cavallo_0.jpg"),Null,r) End Sub
Yes, I understand, but in the meantime I have to do my job too.my problem is not the clipping with the fingers, but the cropping through a pre-set image as in the example I want to cut out only what is inside the t-shirt
yes, obviously the t shirt will have only the transparent inside and the rest outside with a dark background. Okay, I'm waiting for your example in the day. Thanks so muchYes, I understand, but in the meantime I have to do my job too.
You work too
This was easier to do. I'll have the rest when I can. Please note that the exterior of the preset images must have a black background (or any other color you have set)
As soon as I can tyi, I'll set an example for lunch now
ThaaaaankssssssSee this example. I will not give you any more help because I have seen that this question you have asked many times in the forum. (Here1 and Here2)
Be satisfied with this.
View attachment 67189