I am trying to record images which are changed at a set time interval. These are displayed on an imageview. (works something like a movie maker)
For this I am:
1. Drawing these images on a bitmap, this method is repeated over a 50ms interval
2. Using the bitmap data to convert it to yuv data
By using getNV21 method :
http://stackoverflow.com/questions/5960247/convert-bitmap-array-to-yuv-ycbcr-nv21
3. Finally this yuv data is passed FFmpeg recorder, through a method similar to onPreviewFrame, except that the data is from getNV21 method. This method is started by a button click.
What I have achieved:
1. If i dont use clearBitmap(); i get only the first image recorded in the video, even on changing to next image only first image is present throughout the video.
2. So After research on stack overflow many developers suggested clearing the previous imageCache for the next Image. But in my case if i use any of these methods, anywhere,
I get the error; mostly because the getNV21 method is running non stop, and always is expecting pixels flow from the Bitmap.
3. If i try running the methods one after another, by stopping getpixels for a moment by a boolean, i only get a black screen.
Kindly help...!
THANKS.
For this I am:
1. Drawing these images on a bitmap, this method is repeated over a 50ms interval
Code:
private void BitmapUpdate() {
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
try {
new Task1().execute();
} catch (Exception e) {
// TODO: handle exception
}
}
}, 0, 50);
}
class Task1 extends AsyncTask<Void, Void, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
clearBitmap();
}
@Override
protected String doInBackground(Void... arg0) {
onImageDisplayed();
return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
}
}
public void clearBitmap(){
if (imageview != null){
//All the 3 methods below give same error - can't call getpixels() on recycled bitmap
imageview.setDrawingCacheEnabled(false);
//OR
imageview.destroyDrawingCache();
//OR
bitmap.recycle();
}
}
public void onImageDisplayed(){
if (imageview != null) {
imageview.setDrawingCacheEnabled(true);
imageview.buildDrawingCache();
bitmap = imageview.getDrawingCache();
System.out.println(bitmap.getByteCount() + " is bitmap size ");
}
}
2. Using the bitmap data to convert it to yuv data
By using getNV21 method :
http://stackoverflow.com/questions/5960247/convert-bitmap-array-to-yuv-ycbcr-nv21
3. Finally this yuv data is passed FFmpeg recorder, through a method similar to onPreviewFrame, except that the data is from getNV21 method. This method is started by a button click.
What I have achieved:
1. If i dont use clearBitmap(); i get only the first image recorded in the video, even on changing to next image only first image is present throughout the video.
2. So After research on stack overflow many developers suggested clearing the previous imageCache for the next Image. But in my case if i use any of these methods, anywhere,
Code:
imageview.setDrawingCacheEnabled(false);
//OR
imageview.destroyDrawingCache();
//OR
bitmap.recycle();
I get the error; mostly because the getNV21 method is running non stop, and always is expecting pixels flow from the Bitmap.
3. If i try running the methods one after another, by stopping getpixels for a moment by a boolean, i only get a black screen.
Kindly help...!
THANKS.