public static void sendTextBitmap( LiveViewAdapter liveView, int pluginId, String text, int bitmapSizeX, int fontSize, int bitmapSize) { // Empty bitmap and link the canvas to it Bitmap bitmap = null; try { bitmap = Bitmap.createBitmap(bitmapSizeX, bitmapSize, Bitmap.Config.RGB_565); } catch (IllegalArgumentException e) { return; } Canvas canvas = new Canvas(bitmap); // Set the text properties in the canvas TextPaint textPaint = new TextPaint(); textPaint.setTextSize(fontSize); textPaint.setColor(Color.WHITE); // Create the text layout and draw it to the canvas StaticLayout textLayout = new StaticLayout(text, textPaint, bitmapSizeX, Layout.Alignment.ALIGN_CENTER, 1, 1, false); textLayout.draw(canvas); try { liveView.sendImageAsBitmap(pluginId, centerX(bitmap), centerY(bitmap), bitmap); } catch (Exception e) { Log.d(PluginConstants.LOG_TAG, "Failed to send bitmap", e); } }
/** * Sends an image to LiveView and puts it in the middle of the screen * * @param liveView * @param pluginId * @param bitmap * @param path */ public static void sendScaledImage(LiveViewAdapter liveView, int pluginId, Bitmap bitmap) { try { if (liveView != null) { liveView.sendImageAsBitmap(pluginId, centerX(bitmap), centerY(bitmap), bitmap); } } catch (Exception e) { Log.e(PluginConstants.LOG_TAG, "Failed to send image.", e); } }