Android Question Crop Witdh & Height

Douglas Farias

Expert
Licensed User
Longtime User
Hi, i m using canvas to make a crop with rect
this works outputstream JPEG quality 100

ok image save normal but i have one problem with witdh and height



this is the code
B4X:
Sub btaprova_Click
    If salvouprimeira = False Then
    Dim cvs As Canvas
    cvs.Initialize(TouchImageView1)   

    Dim Bitmap1 As Bitmap
    Bitmap1.Initialize3(TouchImageView1.TransformedBitmap)

    Dim SrcRect As Rect
    SrcRect.Initialize( cropimg.Left , cropimg.Top , cropimg.Left + cropimg.Width ,cropimg.Top + cropimg.Height)

    Dim DestRect As Rect
    DestRect.Initialize(0%x,0%y,100%x,100%y)
   
    cvs.DrawBitmap(Bitmap1,SrcRect,DestRect)
    Dim out As OutputStream
    Dim filename As String
    filename = "Thumbnail.png"
    out = File.OpenOutput (fp, filename ,  False)
    cvs.Bitmap.WriteToStream(out,  100, "PNG") 
    out.Close
   
    If File.Exists(fp, "Thumbnail.png") Then
    imgamostra.Bitmap = LoadBitmap(fp, "Thumbnail.png")
    cropimg.SetLayout(25%x, menu.Height, 75%x - 25%x, 80%y)
    salvouprimeira = True
    TouchImageView1.Color = Colors.Black
    End If
    Else
   
    Dim cvs As Canvas
    cvs.Initialize(TouchImageView1)   

    Dim Bitmap1 As Bitmap
    Bitmap1.Initialize3(TouchImageView1.TransformedBitmap)

    Dim SrcRect As Rect
    SrcRect.Initialize( cropimg.Left , cropimg.Top , cropimg.Left + cropimg.Width ,cropimg.Top + cropimg.Height)

    Dim DestRect As Rect
    DestRect.Initialize(0%x,0%y,100%x,100%y)
   
    cvs.DrawBitmap(Bitmap1,SrcRect,DestRect)
    Dim out As OutputStream
    Dim filename As String
    filename = "Background.png"
    out = File.OpenOutput (fp, filename ,  False)
    cvs.Bitmap.WriteToStream(out,  100, "PNG") 
    out.Close
   
    If File.Exists(fp, "Background.png") Then
    bgamostra.Bitmap = LoadBitmapSample(fp, "Background.png", bgamostra.Width, bgamostra.Height)

    TouchImageView1.Color = Colors.Black
    painelconfirmafoto.Visible = True
    painelconfirmafoto.BringToFront
    cropimg.SetLayout(25%x, 35%y, 50%x, 30%y)
    salvouprimeira = False
    btaprova.Visible = False
    btrecusa.Visible = False
    btaprovar.Visible = True
    btrecusar.Visible = True
    btrecusar.BringToFront
    btaprovar.BringToFront
    End If
   
    End If
   
End Sub


B4X:
filename = "Thumbnail.png"
    out = File.OpenOutput (fp, filename ,  False)
    cvs.Bitmap.WriteToStream(out,  100, "PNG") 
    out.Close

the OpenOutput image is saved with
width = 720
height = 1220

why this? i tested on another devices and tablets and save with the same width and height
why this?

can i set witdh and height when i go save the image on WriteToStream(out, 100, "PNG") ?

for exemple
WriteToStream(out, 100, "PNG". witdh = 100 , height = 100 )
 

Douglas Farias

Expert
Licensed User
Longtime User
the size is 800 x 600 image the crop make image croped =
width = 720
height = 1220

this image when i run on square like a crop is normalm but the real image is very strange.
i go search about
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
Here is a example with log.
the log is ever 720x1184 its very strange, i dont set any width and height i dont know where the canvas get this values to make a crop.

the image original on this example have 1920 x 1080


the canvas make a height very big o_O
 

Attachments

  • Crop Sample.zip
    321.1 KB · Views: 331
Upvote 0
Top