B4J Question [SOLVED] Increase bitmap height

jroriz

Active Member
Licensed User
Longtime User
Hi.

I am trying to increase the height of a bitmap, but without distorting the image. It's like a white border above and below.

I want to transform this:

img.jpg


In that:

imgborder.jpg


What I have achieved so far generates a black bitmap ...

meapague.JPEG


My code:
B4X:
Sub AumentarImagem(bmp1 As B4XBitmap) As B4XBitmap
    
    Dim bc As BitmapCreator
    bc.Initialize(bmp1.Width , bmp1.Height * 3)
    Dim r As B4XRect
    r.Initialize(0, bmp1.Height, bmp1.Width, bmp1.Height)
    bc.DrawBitmap(bmp1, r, True)
    Return bc.Bitmap
    
End Sub
 

jroriz

Active Member
Licensed User
Longtime User
Replace:
r.Initialize(0, bmp1.Height, bmp1.Width, bmp1.Height)
by:
r.Initialize(0, bmp1.Height, bmp1.Width, 2 * bmp1.Height)
The last parameter is Bottom, not Height.
Nice.

But now I have a zebra... :)
meapague.JPEG


I fixed the black border with the code below.
It works, but is it the best way?

B4X:
Sub AumentarImagem(bmp1 As B4XBitmap) As B4XBitmap
   
    Dim bc As BitmapCreator
    bc.Initialize(bmp1.Width , bmp1.Height * 3)
   
    Dim r As B4XRect

    r.Initialize(0,0,bc.mWidth, bc.mHeight)

    Dim xui As XUI
    bc.DrawRect(r, xui.Color_White, True, 1)

    r.Initialize(0, bmp1.Height, bmp1.Width, bmp1.Height*2)
    bc.DrawBitmap(bmp1, r, True)
    Return bc.Bitmap
   
End Sub
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Similar code:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show
   ImageView1.SetBitmap(CreateTallerBitmap(xui.LoadBitmap(File.DirAssets, "img.jpg"), ImageView1.Height))
End Sub

Sub CreateTallerBitmap(Input As B4XBitmap, NewHeight As Int) As B4XBitmap
   Dim NewBC As BitmapCreator
   NewBC.Initialize(Input.Width, NewHeight)
   NewBC.DrawRect(NewBC.TargetRect, xui.Color_White, True, 0)
   Dim r As B4XRect
   r.Initialize(0, NewHeight / 2 - Input.Height / 2, Input.Width, 0)
   r.Height = Input.Height
   NewBC.DrawBitmap(Input, r, True)
   Return NewBC.Bitmap
End Sub
 
Upvote 0
Top