Here is the inline java code, in order to create bitmap from a view:
and you can call it like this:
At this example i use Ultimate list view and i create a bitmap from a list view item.
B4X:
#if Java
//create bitmap from the ScrollView
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.graphics.Color;
public static Bitmap getBitmapFromView(View view, int height, int width) {
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Drawable bgDrawable = view.getBackground();
if (bgDrawable != null)
bgDrawable.draw(canvas);
else
canvas.drawColor(Color.WHITE);
view.draw(canvas);
return bitmap;
}
#End If
and you can call it like this:
B4X:
Sub btnShare_Click
indexPost = ULV1.FindIDInVisibleItems(Sender)
Dim nativeMe As JavaObject
nativeMe.InitializeContext
Private Bitmap1 As Bitmap
Bitmap1=nativeMe.RunMethod("getBitmapFromView", Array(ULV1.GetVisiblePanels(ULV1.GetPositionForID(indexPost,True)),ULV1.GetVisiblePanels(ULV1.GetPositionForID(indexPost,True)).Height-50dip,100%x))
Dim Out As OutputStream
Out = File.OpenOutput(Starter.directory, "Test.png", False)
Log(Starter.directory)
Bitmap1.WriteToStream(Out, 100, "PNG")
Out.Close
End Sub
At this example i use Ultimate list view and i create a bitmap from a list view item.