Android Question scrolling image

freedom2000

Well-Known Member
Licensed User
Hi all,

I would like to code a spectrogram app to dispaly FFT of audio file.

The result would be something like this :


The image is coming from the right to to the left, one column at a time when a new FFT is performed on the audio stream. Vertical axis dispays the amplitude of the FFT for each frequency.
Currently the FFT is OK, audio stream as well.

But I do have a very stupid question : I don't know how to perform the scrolling...

It seems easy to paint into a canvas the new right most column

But what is the best solution to clip the image (but the first column) and to shift it one pixel to the left ?

Thank you for your help
 

lemonisdead

Well-Known Member
Licensed User
Hello,
I am not an expert. Looking for an answer, I wondered if you have tried this. Sorry if it is not a solution.
 

sorex

Expert
Licensed User
copy the bitmap/canvas data from pixel 1 to maxwidth to pixel 0.
then draw a new line at maxwidth.
 

sorex

Expert
Licensed User
not sure if you can do it with 1 canvas so worst case you need 2.

so you'll need the canvas drawbitmap method to copy a region of bitmap data.

search the forum for drawbitmap, there should pop up some examples.

if it is too slow you can use 2 canvas that you move around and progressively fill with data
and when required move it back to the right side of the screen when it goes offscreen on the left.
 

freedom2000

Well-Known Member
Licensed User
thanks to put me on the track

I was just trying this code.
The image is displayed but never moves ...

It was supposed to display a full screen widht image and then to move it with the timer, one pixel left each time

There should be a stupid error but where ???

B4X:
'Activity module
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

    Dim Timer1 As Timer
End Sub
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim bmpImage As Bitmap
    Dim cvsMain As Canvas
    Dim rectSrc, rectDest As Rect
End Sub
Sub Activity_Create(FirstTime As Boolean)
    cvsMain.Initialize(Activity)
    bmpImage.Initialize(File.DirAssets,"test.jpg")
    rectSrc.Initialize(1, 0, bmpImage.Width, bmpImage.Height)
    rectDest.Initialize(0, 0, bmpImage.Width-1, bmpImage.Height )
    Timer1.Initialize("Timer1",10)
    Timer1.Enabled = True
End Sub
Sub Activity_Resume

End Sub
Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub Timer1_Tick
        rectSrc.Initialize(1, 0, bmpImage.Width, bmpImage.Height)
        rectDest.Initialize(0, 0, bmpImage.Width-1, bmpImage.Height )
        cvsMain.Drawbitmap(bmpImage, rectSrc, rectDest)
        Activity.Invalidate
End Sub
 

sorex

Expert
Licensed User
that is probably because you always reference to that loaded picture which remains static so you copy always the same part back to the canvas.

I'll see if I can mod it for you.
 

sorex

Expert
Licensed User
here you go, this creates the scrolling stuff you see in the attachment
(the bugs at the bottom is from the screenshotting, it's not like that on the phone)
B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

'Activity module
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

    Dim Timer1 As Timer
End Sub
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim bmpImage As Bitmap
    Dim cvsMain As Canvas
    Dim rectSrc, rectDest As Rect
End Sub
Sub Activity_Create(FirstTime As Boolean)
    cvsMain.Initialize(Activity)
    bmpImage=cvsMain.Bitmap
'    bmpImage.Initialize(File.DirAssets,"test.jpg")
    rectSrc.Initialize(1, 0, bmpImage.Width, bmpImage.Height)
    rectDest.Initialize(0, 0, bmpImage.Width-1, bmpImage.Height )
    Timer1.Initialize("Timer1",10)
    Timer1.Enabled = True
End Sub
Sub Activity_Resume

End Sub
Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub Timer1_Tick
        rectSrc.Initialize(1, 0, bmpImage.Width, bmpImage.Height)
        rectDest.Initialize(0, 0, bmpImage.Width-1, bmpImage.Height )
        cvsMain.Drawbitmap(bmpImage, rectSrc, rectDest)
        Dim linesize As Int
        linesize=Rnd(1,bmpImage.Height)
        cvsMain.DrawLine(bmpImage.Width-1,0,bmpImage.Width-1,bmpImage.Height,Colors.Black,1dip)      
        cvsMain.DrawLine(bmpImage.Width-1,(bmpImage.Height-linesize)/2,bmpImage.Width-1,((bmpImage.Height-linesize)/2)+linesize,Colors.White,1dip)
        Activity.Invalidate
End Sub
 

Attachments

Top