I have created a custom WebView, which will be used to play a gif file. Now I need to draw this to my canvas in a specific position and using a set size.
However, I am not entirly sure how I can convert this webView containing Gif into a Bitmap so that I can insert it into the correct location on my Canvas.
My WebView Class:
public class finishWebView extends WebView
{
public finishWebView(Context context, String path)
{
super(context);
loadUrl(path);
}
}
Getting the raw resource for main Activity:
finishWebView view = new finishWebView(context, "file:///android_asset/test.gif");
The orginal code to convert my image to the correct size and insert into canvas:
finish = BitmapFactory.decodeResource(getResources(), R.drawable.finish);
finish = Bitmap.createScaledBitmap(finish, (PhoneWidth / 5), (PhoneWidth / 5), true);
protected void onDraw(Canvas canvas)
{
canvas.drawBitmap(finish, (j * totalCellWidth), (i * totalCellHeight), null);
}
So essentially, I need to work out a way to draw the webView with gif image displaying onto the specified locations within my canvas, similar to what I am currently doing with 'canvas.drawBitmap(...)'.
----------------------------------- EDIT ----------------------------------------
Using the code snippet mentioned provided by mikejonesguy, I have got to here, however this now just displays a blank screen.
public static Bitmap createBitmapFromView(View v) {
Bitmap b = Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565);
Canvas c = new Canvas(b);
v.draw(c);
return b;
}
// Within onDraw
GIFView gifView = new GIFView(context);
canvas.drawBitmap(createBitmapFromView(gifView), (j * totalCellWidth), (i * totalCellHeight), null);
I have tested my GIFView on normal xml layout pages and it works correctly, just cannot get it inserted into my canvas.