Android Question Save only the image inside the panel?!

Matteo Granatiero

Active Member
Licensed User
Longtime User
I need to save the image that appears only inside the panel as in the image. Thanks in advance
 

Attachments

  • .png
    .png
    360.3 KB · Views: 714
Try this:
Code: Copy
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
 
Upvote 0
Try this:
Code: Copy
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?
 

Attachments

  • mare_trasparente.png
    mare_trasparente.png
    370.2 KB · Views: 671
Upvote 0
Use the Path to select the part and cut out with canvas.

Is the figure cut out manually or do you have pre-established shapes?
 
Upvote 0
Use the Path to select the part and cut out with canvas.

Is the figure cut out manually or do you have pre-established shapes?
pre-established shapes! can you make me an example directly? because I really can not do it
I enclose the pre-established form
 

Attachments

  • t shirt.png
    t shirt.png
    26.2 KB · Views: 670
Upvote 0
pre-established shapes! can you make me an example directly? because I really can not do it
I enclose the pre-established form
I'm off-site I'm sorry I can not now
 
Upvote 0
First example: Freehand image cropping.
video.gif

Code: Copy
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
 

Attachments

Upvote 0
First example: Freehand image cropping.
View attachment 67180
Code: Copy
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-shirt
 

Attachments

  • mare_trasparente.png
    mare_trasparente.png
    370.2 KB · Views: 733
Upvote 0
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, I understand, but in the meantime I have to do my job too. :-p
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
 
Upvote 0
Yes, I understand, but in the meantime I have to do my job too. :p
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
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 much:);):(
 
Upvote 0
The best thing would be to recharge the points of the path from the frame and apply it to the photo.

To do this you have to create an algorithm that from the frame image you earn points, in itself it is not impossible and I have got at least 2 interesting ideas, but ... they would take time and if I did an algorithm like that I would keep it for myself . :-p
 
Upvote 0
Back
Top