Android : Best practice to properly render bitmap based on a real time signal and scale it

on Tuesday, October 28, 2014


Context


Basically i'm getting the Blue value between 0 and 255 of the central pixel of the camera frame, after converting from YUV to ARGB i "plot" the Blue value (0-255) in a View, using a int[frames*255] bitmap surface, so i can use it as a plan to draw my values in time, simply colouring the value-pixel of my surface, obviously i keep the old ones to see an time extended trend.


Problem


It's difficult to see, it's pretty awful and i think that this not the better way to do it. I will be more clear with this picture.


The connection is that if the blue value is 125 i color the 125th pixel of the bitmap array, and when a new value arrives i copy the line forward.


 This is a sinusoidal signal that i made to happen by pointing my camera to a 1Hz blue signal


This is a sinusoidal signal that i made to happen by pointing my camera to a 1Hz blue blinking window. Every time i pick the value from 0-255 and i colour the surface[value] pixel, then i move forward the old ones.


My .xml code



<RelativeLayout ... >

<FrameLayout
android:id="@+id/camera_preview"
android:layout_width="640px"
android:layout_height="480px"
/>

<FrameLayout
android:id="@+id/zoomed_pixel"
android:layout_toRightOf="@id/camera_preview"
android:layout_width="100px"
android:layout_height="100px"
/>
<FrameLayout
android:id="@+id/graph"
android:layout_toRightOf="@id/zoomed_pixel"
android:layout_width="255px" // so i can take the value
android:layout_height="180px" //i get 30 frame per second so i represent 6 seconds
/>

<Button ... />



</RelativeLayout>


My Graph class



public class Graph extends View {

private int width=255;
private int height=180;
private int[] surface new int[width*height];;


public ColorBitmap(Context context) {
super(context);

//INIT MY SURFACE TO A WHITE BACKGROUND
for(int i=0; i<surface.length;i++)
surface[i]=0xffffffff;
}


@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);

canvas.drawBitmap(surface, 0, w, 0, 0, w, h, false, paint);

}

public void pushValue(int value){

//THE FIRST LINE, IS THE ONE THAT I COLOR EVERY TIME THE VALUE ARRIVES
int p =255;

//TO COPY THE OLD ONE
int tmp[]=new int[255];

for(int i=1;i<height; i++){
for(int k=0;k<width;k++){
tmp[k]=surface[p];
surface[p]=surface[p-255];
surface[p-255]=tmp [k];
p++;
}
}

//I WANT THE FIRST 255 PIXELS TO BE WHITE
for(int i=0;i<width;i++)
surface[i]=0xffffffff;

//THEN I COLOR THE CORRISPONDING PIXEL IN BLUE
surface[value]=0xff;

}

}


What I'm asking


Does anyone know a better way to represent the trend of the signal (maybe by stretching and scaling my bitmap? or does exist something that given values in real time it gives a graph that change in time?)


0 comments:

Post a Comment