B4J Question Shift a bitmap vertically

yo3ggx

Active Member
Licensed User
Longtime User
Hello,

How can I shift a bitmap vertically with 1 pixel in B4J and then add a new line at the bottom from a byte array?
In b4A I'm using BitmapExtended library, but this one is not available in B4J.

Thank you.
 

kimstudio

Active Member
Licensed User
Longtime User
B4J Internal library jBitmapCreator has pixel random-access function GetColor/ARGB and SetColor/ARGB.
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
(Only if you are using Windows...)

Get the first example from HERE (jOpenCV_Sample01_ImageProcessing) open any picture (first icon: folder), and play with it.

1658260656924.png



Once you have it running I can guide you to add any line to the bitmap based on arbitrary data.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I know, but working at pixel level is not fast enough.
BitmapCreator is very fast when used correctly.
It takes 0ms to shift an image vertically.

java_ok3eMfXPkF.gif


B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private ImageView1 As B4XView
    Private bc1 As BitmapCreator
End Sub

Public Sub Initialize
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Dim bmp As B4XBitmap = xui.LoadBitmap(File.DirAssets, "33472.jpg")
    bc1.Initialize(bmp.Width, bmp.Height)
    bc1.CopyPixelsFromBitmap(bmp)
    bc1.SetBitmapToImageView(bc1.Bitmap, ImageView1)
End Sub

Private Sub Button1_Click
    ShiftUpRow(bc1, 10)
    bc1.SetBitmapToImageView(bc1.Bitmap, ImageView1)
End Sub

Private Sub ShiftUpRow (bc As BitmapCreator, NumberOfRows As Int)
    Bit.ArrayCopy(bc.Buffer, bc.mWidth * 4 * NumberOfRows, bc.Buffer, 0, bc.mWidth * 4 * (bc.mHeight - NumberOfRows))
End Sub
 
Upvote 0

yo3ggx

Active Member
Licensed User
Longtime User
(Only if you are using Windows...)

Get the first example from HERE (jOpenCV_Sample01_ImageProcessing) open any picture (first icon: folder), and play with it.
...
Once you have it running I can guide you to add any line to the bitmap based on arbitrary data.
Thank you, but is much to complex for such a simple operation.
 
Upvote 0

yo3ggx

Active Member
Licensed User
Longtime User
BitmapCreator is very fast when used correctly.
It takes 0ms to shift an image vertically.
Your suggestion works perfect for my needs.
Everything solved in just two lines of code to shift one line up and replace the last line from bottom with a line of integers (colors) as an integer array (linePixels) converted to a byte array.

Initialization:
    Private imgSpec As B4XView
    Dim bmc As BitmapCreator
    Dim linePixels() As Int
    Dim bc as ByteConverter

B4X:
bc.LittleEndian = True
Bit.ArrayCopy(bmc.Buffer, bmc.mWidth * 4, bmc.Buffer, 0, bmc.mWidth * 4 * (bmc.mHeight - 1))    
Bit.ArrayCopy(bc.IntsToBytes(linePixels),0,bmc.buffer,bmc.mWidth * 4 * (bmc.mHeight - 1),bmc.mWidth * 4)             
bmc.SetBitmapToImageView(bmc.Bitmap,imgSpec)

Using now a B4XView instead of an B4XImageView, how can i force the bitmap to fill the B4XView?

Thank you.
 
Upvote 0

yo3ggx

Active Member
Licensed User
Longtime User
I didn't use B4XImageView in my code. It is an ImageView declared as B4XView.
This is what I said. How can I fill the B4XView with the bitmap, as the bitmap is smaller than the ImageView (declared as a B4XView)?
 
Upvote 0
Top