Android Question Save only the image inside the panel?!

Matteo Granatiero

Active Member
Licensed 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: 328

Star-Dust

Expert
Licensed User
Longtime User
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
 
Upvote 0

Matteo Granatiero

Active Member
Licensed User
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?
 

Attachments

  • mare_trasparente.png
    mare_trasparente.png
    370.2 KB · Views: 311
Upvote 0

Matteo Granatiero

Active Member
Licensed User
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
if I wanted to do this kind of clipping?
 

Attachments

  • mare_trasparente.png
    mare_trasparente.png
    370.2 KB · Views: 243
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
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

Matteo Granatiero

Active Member
Licensed User
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: 287
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
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

Star-Dust

Expert
Licensed User
Longtime User
First example: Freehand image cropping.
video.gif

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
 

Attachments

  • cut-bitmap.zip
    56.8 KB · Views: 304
Upvote 0

Matteo Granatiero

Active Member
Licensed User
First 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
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: 247
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
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

Matteo Granatiero

Active Member
Licensed User
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

Star-Dust

Expert
Licensed User
Longtime User
See 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.

ezgif.com-video-to-gif.gif
 

Attachments

  • FrameCrop.zip
    73 KB · Views: 325
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
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
Top