List of usage examples for android.graphics Canvas drawColor
public void drawColor(@ColorInt int color)
From source file:com.binu.LogarithmicGraph.DrawGraphAsyncTask.java
@Override protected Object doInBackground(Object[] params) { Bitmap bitmapBackground = Bitmap.createBitmap(mViewWidth, mViewHeight, Bitmap.Config.ARGB_8888); Canvas canvasBackground = new Canvas(bitmapBackground); Paint paint = new Paint(); paint.setStrokeWidth(1f);//from w w w. ja va 2 s . c o m int starty = 0; int endy = mViewHeight; canvasBackground.drawColor(Color.BLACK); double ratio = Math.pow(Math.E, Math.log(MAX_FREQUENCY / MIN_FREQUENCY) / mViewWidth); mLogScaledX_values = new double[mViewWidth]; for (int i = 0; i < mViewWidth; i++) { if (i == 0) { mLogScaledX_values[i] = 20; } else { mLogScaledX_values[i] = mLogScaledX_values[i - 1] * ratio; } } //Major lines for (int i = 0; i < MAJOR_GRIDLINE_POINTS.length; i++) { paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color)); float xStart = (float) findNearestNumberPosition(mLogScaledX_values, MAJOR_GRIDLINE_POINTS[i]); float textSize = (getPixelDensity(mContext) * mLabelTextSize) / 480; paint.setTextSize(textSize); Log.i("Density", "" + getPixelDensity(mContext)); if (Math.round(MAJOR_GRIDLINE_POINTS[i]) == 20) { if (isShowLabels()) canvasBackground.drawText(getFormattedLabel(MAJOR_GRIDLINE_POINTS[i]), xStart + (getPixelDensity(mContext) * 10) / 480, endy - (getPixelDensity(mContext) * 10) / 480, paint); } else if (Math.round(MAJOR_GRIDLINE_POINTS[i]) == 20000) { if (isShowLabels()) canvasBackground.drawText(getFormattedLabel(MAJOR_GRIDLINE_POINTS[i]), xStart - (getPixelDensity(mContext) * 70) / 480, endy - (getPixelDensity(mContext) * 10) / 480, paint); } else { if (isShowLabels()) canvasBackground.drawText(getFormattedLabel(MAJOR_GRIDLINE_POINTS[i]), xStart - (getPixelDensity(mContext) * 30) / 480, endy - (getPixelDensity(mContext) * 10) / 480, paint); canvasBackground.drawLine(xStart, starty, xStart + 1, endy, paint); } } //Minor lines for (int i = 0; i < MINOR_GRIDLINE_POINTS.length; i++) { paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color_dull)); float xStart = (float) findNearestNumberPosition(mLogScaledX_values, MINOR_GRIDLINE_POINTS[i]); canvasBackground.drawLine(xStart, starty, xStart + 1, endy, paint); if (isShowLabels()) { paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color)); if (MINOR_GRIDLINE_POINTS[i] == 50 || MINOR_GRIDLINE_POINTS[i] == 500 || MINOR_GRIDLINE_POINTS[i] == 5000) canvasBackground.drawText(getFormattedLabel(MINOR_GRIDLINE_POINTS[i]), xStart - (getPixelDensity(mContext) * 30) / 480, endy - (getPixelDensity(mContext) * 10) / 480, paint); } } float[] Y_points = calculateGraphYAxis(); float div = mViewHeight / (Y_points.length - 1); //Level lines for (int i = 0; i < Y_points.length - 1; i++) { paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color_dull)); canvasBackground.drawLine(0, div * (i + 1), mViewWidth, (div * (i + 1)) + 1, paint); } //Level labels if (isShowLabels()) { for (int i = 0; i < Y_points.length; i++) { paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color)); if (i == 0) canvasBackground.drawText("dB", 0, (div * i) + (getPixelDensity(mContext) * 50) / 480, paint); else if (i == Y_points.length - 1) canvasBackground.drawText("", 0, div * i, paint); else canvasBackground.drawText("" + Math.round(Y_points[i]), 0, div * i, paint); } } BitmapDrawable drawable = new BitmapDrawable(mContext.getResources(), bitmapBackground); mDrawableBackground = drawable; //Plotting the curve points Bitmap bitmapForeground = Bitmap.createBitmap(mViewWidth, mViewHeight, Bitmap.Config.ARGB_8888); Canvas canvasForeground = new Canvas(bitmapForeground); Paint plotPaint = new Paint(); plotPaint.setStyle(Paint.Style.STROKE); plotPaint.setStrokeCap(Paint.Cap.ROUND); plotPaint.setStrokeWidth(PLOT_THICKNESS); plotPaint.setAntiAlias(true); plotPaint.setColor(ContextCompat.getColor(mContext, R.color.graph_plot_color)); for (int i = 0; i < X_values.length; i++) { // canvasForeground.drawCircle(i, mViewHeight - mPlotPoint[i], 2f, plotPaint); /*float startX, float startY, float stopX, float stopY, @NonNull Paint paint*/ float startX = (float) getGetPixelValueForX(X_values[i]); float startY = mViewHeight - getPixelValueFromdB((int) GAIN_MAX, (int) GAIN_MIN, mViewHeight, Y_values[i]); float stopX; float stopY; if (i == X_values.length - 1) { stopX = (float) getGetPixelValueForX(X_values[i]); stopY = mViewHeight - getPixelValueFromdB((int) GAIN_MAX, (int) GAIN_MIN, mViewHeight, Y_values[i]); } else { stopX = (float) getGetPixelValueForX(X_values[i + 1]); stopY = mViewHeight - getPixelValueFromdB((int) GAIN_MAX, (int) GAIN_MIN, mViewHeight, Y_values[i + 1]); } canvasForeground.drawLine(startX, startY, stopX, stopY, plotPaint); } BitmapDrawable drawableFore = new BitmapDrawable(mContext.getResources(), bitmapForeground); mDrawableForeground = drawableFore; return null; }
From source file:com.s8launch.cheil.facetracker.MultiTrackerActivity.java
public Bitmap getBitmapFromView(View view) { view.setBackgroundColor(Color.TRANSPARENT); //Define a bitmap with the same size as the view Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); //Bind a canvas to it Canvas canvas = new Canvas(returnedBitmap); //Get the view's background Drawable bgDrawable = view.getBackground(); if (bgDrawable != null) //has background drawable, then draw it on the canvas bgDrawable.draw(canvas);/*from w w w . j a va 2s . co m*/ else //does not have background drawable, then draw white background on the canvas canvas.drawColor(Color.WHITE); // draw the view on the canvas view.draw(canvas); //return the bitmap return returnedBitmap; }
From source file:com.nikhilnayak.games.octoshootar.ui.fragments.GameScoreFragment.java
private Bitmap getBitmapToShare() { final View fragmentView = GameScoreFragment.this.getView(); final Paint paint = new Paint(); Bitmap bitmap;//from w ww. j a v a 2 s. c o m // Get the game name. final View gameName = fragmentView.findViewById(R.id.fragment_score_game_mode_name); final int gameNameWidth = gameName.getWidth(); final int gameNameHeight = gameName.getHeight(); // Get the grade card. final View gradeCard = fragmentView.findViewById(R.id.result_card_grade); final int gradeCardWidth = gradeCard.getWidth(); final int gradeCardHeight = gradeCard.getHeight(); // Get the details card. final View detailsCard = fragmentView.findViewById(R.id.result_card_details); final int detailsCardWidth = detailsCard.getWidth(); final int detailsCardHeight = detailsCard.getHeight(); // Define some padding and a margin between the elements final int padding = 30; final int margin = 50; // Get the bitmap dimension. int bitmapWidth = Math.max(gameNameWidth, Math.max(gradeCardWidth, detailsCardWidth)) + padding; int bitmapHeight = padding + gameNameHeight + margin + gradeCardHeight + margin + detailsCardHeight; // Compute the left/top for bitmap drawing final int gameNameLeft = bitmapWidth / 2 - gameNameWidth / 2; final int gameNameTop = padding / 2 + margin / 2; final int gradeCardLeft = bitmapWidth / 2 - gradeCardWidth / 2; final int gradeCardTop = padding / 2 + gameNameHeight + margin; final int detailsCardLeft = bitmapWidth / 2 - detailsCardWidth / 2; final int detailsCardTop = padding / 2 + gameNameHeight + margin + gradeCardHeight + margin; // Initialize a bitmap with a canvas. Bitmap bitmapToShare = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmapToShare); canvas.drawColor(GameScoreFragment.this.getResources().getColor(R.color.background_grey)); // Draw the game name gameName.setDrawingCacheEnabled(true); bitmap = gameName.getDrawingCache(true); canvas.drawBitmap(bitmap, gameNameLeft, gameNameTop, paint); gameName.setDrawingCacheEnabled(false); bitmap.recycle(); bitmap = null; // Draw the grade card. gradeCard.setDrawingCacheEnabled(true); bitmap = gradeCard.getDrawingCache(true); canvas.drawBitmap(bitmap, gradeCardLeft, gradeCardTop, paint); gradeCard.setDrawingCacheEnabled(false); bitmap.recycle(); bitmap = null; // Draw the details card. detailsCard.setDrawingCacheEnabled(true); bitmap = detailsCard.getDrawingCache(true); canvas.drawBitmap(bitmap, detailsCardLeft, detailsCardTop, paint); detailsCard.setDrawingCacheEnabled(false); bitmap.recycle(); bitmap = null; return bitmapToShare; }
From source file:com.pablog178.pdfcreator.android.PdfcreatorModule.java
private void generateImageFunction(HashMap args) { if (args.containsKey("fileName")) { Object fileName = args.get("fileName"); if (fileName instanceof String) { this.fileName = (String) fileName; Log.i(PROXY_NAME, "fileName: " + this.fileName); }// w w w . ja v a 2 s .c o m } else return; if (args.containsKey("view")) { Object viewObject = args.get("view"); if (viewObject instanceof TiViewProxy) { TiViewProxy viewProxy = (TiViewProxy) viewObject; this.view = viewProxy.getOrCreateView(); if (this.view == null) { Log.e(PROXY_NAME, "NO VIEW was created!!"); return; } Log.i(PROXY_NAME, "view: " + this.view.toString()); } } else return; TiBaseFile file = TiFileFactory.createTitaniumFile(this.fileName, true); Log.i(PROXY_NAME, "file full path: " + file.nativePath()); try { final int PDF_WIDTH = 612; final int PDF_HEIGHT = 792; Resources appResources = app.getResources(); OutputStream outputStream = file.getOutputStream(); int viewWidth = 1600; int viewHeight = 1; WebView view = (WebView) this.view.getNativeView(); if (TiApplication.isUIThread()) { viewWidth = view.capturePicture().getWidth(); viewHeight = view.capturePicture().getHeight(); if (viewWidth <= 0) { viewWidth = 1300; } if (viewHeight <= 0) { viewHeight = 2300; } } else { Log.e(PROXY_NAME, "NO UI THREAD"); } Log.i(PROXY_NAME, "viewWidth: " + viewWidth); Log.i(PROXY_NAME, "viewHeight: " + viewHeight); Bitmap viewBitmap = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888); float density = appResources.getDisplayMetrics().density; Canvas canvas = new Canvas(viewBitmap); Matrix matrix = new Matrix(); Drawable bgDrawable = view.getBackground(); if (bgDrawable != null) { bgDrawable.draw(canvas); } else { canvas.drawColor(Color.WHITE); } view.draw(canvas); float scaleFactorWidth = 1 / ((float) viewWidth / (float) PDF_WIDTH); float scaleFactorHeight = 1 / ((float) viewHeight / (float) PDF_HEIGHT); Log.i(PROXY_NAME, "scaleFactorWidth: " + scaleFactorWidth); Log.i(PROXY_NAME, "scaleFactorHeight: " + scaleFactorHeight); matrix.setScale(scaleFactorWidth, scaleFactorWidth); Bitmap imageBitmap = Bitmap.createBitmap(PDF_WIDTH, PDF_HEIGHT, Bitmap.Config.ARGB_8888); Canvas imageCanvas = new Canvas(imageBitmap); imageCanvas.drawBitmap(viewBitmap, matrix, null); imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream); sendCompleteEvent(); } catch (Exception exception) { Log.e(PROXY_NAME, "Error: " + exception.toString()); sendErrorEvent(exception.toString()); } }
From source file:com.yanzhenjie.durban.view.OverlayView.java
/** * This method draws dimmed area around the crop bounds. * * @param canvas - valid canvas object/*w w w . jav a 2 s. co m*/ */ protected void drawDimmedLayer(@NonNull Canvas canvas) { canvas.save(); if (mCircleDimmedLayer) canvas.clipPath(mCircularPath, Region.Op.DIFFERENCE); else canvas.clipRect(mCropViewRect, Region.Op.DIFFERENCE); canvas.drawColor(mDimmedColor); canvas.restore(); if (mCircleDimmedLayer) { // Draw 1px stroke to fix antialias canvas.drawCircle(mCropViewRect.centerX(), mCropViewRect.centerY(), Math.min(mCropViewRect.width(), mCropViewRect.height()) / 2.f, mDimmedStrokePaint); } }
From source file:net.osmand.plus.views.controls.DynamicListView.java
/** * Returns a bitmap showing a screenshot of the view passed in. */// w w w . j a v a 2 s. c o m private Bitmap getBitmapFromView(View v) { Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); v.draw(canvas); Bitmap bitmapOut = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvasOut = new Canvas(bitmapOut); canvasOut.drawColor(Color.TRANSPARENT); Paint p = new Paint(); p.setAlpha(200); canvasOut.drawBitmap(bitmap, 0, 0, p); return bitmapOut; }
From source file:com.propelics.pdfcreator.PdfcreatorModule.java
private void generateiTextPDFfunction(HashMap args) { Log.d(PROXY_NAME, "generateiTextPDFfunction()"); String filename = ""; TiUIView webview = null;// w ww. j a v a2 s .c o m int quality = 100; try { if (args.containsKey("filename")) { filename = (String) args.get("filename"); Log.d(PROXY_NAME, "filename: " + filename); } else return; if (args.containsKey("webview")) { TiViewProxy viewProxy = (TiViewProxy) args.get("webview"); webview = viewProxy.getOrCreateView(); Log.d(PROXY_NAME, "webview: " + webview.toString()); } else return; if (args.containsKey("quality")) { quality = TiConvert.toInt(args.get("quality")); } TiBaseFile file = TiFileFactory.createTitaniumFile(filename, true); Log.d(PROXY_NAME, "file full path: " + file.nativePath()); OutputStream outputStream = file.getOutputStream(); final int MARGIN = 0; final float PDF_WIDTH = PageSize.LETTER.getWidth() - MARGIN * 2; // A4: 595 //Letter: 612 final float PDF_HEIGHT = PageSize.LETTER.getHeight() - MARGIN * 2; // A4: 842 //Letter: 792 final int DEFAULT_VIEW_WIDTH = 980; final int DEFAULT_VIEW_HEIGHT = 1384; int viewWidth = DEFAULT_VIEW_WIDTH; int viewHeight = DEFAULT_VIEW_HEIGHT; Document pdfDocument = new Document(PageSize.LETTER, MARGIN, MARGIN, MARGIN, MARGIN); PdfWriter docWriter = PdfWriter.getInstance(pdfDocument, outputStream); Log.d(PROXY_NAME, "PDF_WIDTH: " + PDF_WIDTH); Log.d(PROXY_NAME, "PDF_HEIGHT: " + PDF_HEIGHT); WebView view = (WebView) webview.getNativeView(); if (TiApplication.isUIThread()) { viewWidth = view.capturePicture().getWidth(); viewHeight = view.capturePicture().getHeight(); if (viewWidth <= 0) { viewWidth = DEFAULT_VIEW_WIDTH; } if (viewHeight <= 0) { viewHeight = DEFAULT_VIEW_HEIGHT; } } else { Log.e(PROXY_NAME, "NO UI THREAD"); viewWidth = DEFAULT_VIEW_WIDTH; viewHeight = DEFAULT_VIEW_HEIGHT; } view.setLayerType(View.LAYER_TYPE_SOFTWARE, null); Log.d(PROXY_NAME, "viewWidth: " + viewWidth); Log.d(PROXY_NAME, "viewHeight: " + viewHeight); float scaleFactorWidth = 1 / (viewWidth / PDF_WIDTH); float scaleFactorHeight = 1 / (viewHeight / PDF_HEIGHT); Log.d(PROXY_NAME, "scaleFactorWidth: " + scaleFactorWidth); Log.d(PROXY_NAME, "scaleFactorHeight: " + scaleFactorHeight); Bitmap viewBitmap = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888); Canvas viewCanvas = new Canvas(viewBitmap); // Paint paintAntialias = new Paint(); // paintAntialias.setAntiAlias(true); // paintAntialias.setFilterBitmap(true); Drawable bgDrawable = view.getBackground(); if (bgDrawable != null) { bgDrawable.draw(viewCanvas); } else { viewCanvas.drawColor(Color.WHITE); } view.draw(viewCanvas); TiBaseFile pdfImg = createTempFile(filename); viewBitmap.compress(Bitmap.CompressFormat.PNG, quality, pdfImg.getOutputStream()); FileInputStream pdfImgInputStream = new FileInputStream(pdfImg.getNativeFile()); byte[] pdfImgBytes = IOUtils.toByteArray(pdfImgInputStream); pdfImgInputStream.close(); pdfDocument.open(); float yFactor = viewHeight * scaleFactorWidth; int pageNumber = 1; do { if (pageNumber > 1) { pdfDocument.newPage(); } pageNumber++; yFactor -= PDF_HEIGHT; Image pageImage = Image.getInstance(pdfImgBytes, true); // Image pageImage = Image.getInstance(buffer.array()); pageImage.scalePercent(scaleFactorWidth * 100); pageImage.setAbsolutePosition(0f, -yFactor); pdfDocument.add(pageImage); Log.d(PROXY_NAME, "yFactor: " + yFactor); } while (yFactor > 0); pdfDocument.close(); sendCompleteEvent(filename); } catch (Exception exception) { sendErrorEvent(exception); } }
From source file:com.joanzapata.PDFViewActivity.java
public byte[] getBitmapFromView(View view) { // Define a bitmap with the same size as the view Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); // Bind a canvas to it Canvas canvas = new Canvas(returnedBitmap); // Get the view's background Drawable bgDrawable = view.getBackground(); if (bgDrawable != null) // has background drawable, then draw it on the canvas bgDrawable.draw(canvas);//from ww w . j ava 2s . co m else // does not have background drawable, then draw white background on // the canvas canvas.drawColor(Color.WHITE); // draw the view on the canvas view.draw(canvas); ByteArrayOutputStream stream = new ByteArrayOutputStream(); returnedBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] byteArray = stream.toByteArray(); return byteArray; }
From source file:com.netcompss.ffmpeg4android_client.BaseVideo.java
private Bitmap ProcessingBitmapTwo(Bitmap bm1, Bitmap bm2) { Bitmap newBitmap = null;//from w ww . j a va2 s. co m int w; if (bm1.getWidth() >= bm2.getWidth()) { w = bm1.getWidth(); } else { w = bm2.getWidth(); } int h; if (bm1.getHeight() >= bm2.getHeight()) { h = bm1.getHeight(); } else { h = bm2.getHeight(); } Config config = bm1.getConfig(); if (config == null) { config = Bitmap.Config.ARGB_4444; } newBitmap = Bitmap.createBitmap(w, h, config); Canvas newCanvas = new Canvas(newBitmap); newCanvas.drawColor(Color.WHITE); if (bm2.getWidth() == bm2.getHeight()) { newCanvas.drawBitmap(bm2, (w - bm2.getWidth()) / 2, (h - bm2.getHeight()) / 2, null); } else { newCanvas.drawBitmap(bm2, (w / 2) - (bm2.getWidth() / 2), (h / 2) - (bm2.getHeight() / 2), null); } return newBitmap; }
From source file:com.pablog178.pdfcreator.android.PdfcreatorModule.java
private void generateiTextPDFfunction(HashMap args) { if (args.containsKey("fileName")) { Object fileName = args.get("fileName"); if (fileName instanceof String) { this.fileName = (String) fileName; Log.i(PROXY_NAME, "fileName: " + this.fileName); }//www. j a va2s. co m } else return; if (args.containsKey("view")) { Object viewObject = args.get("view"); if (viewObject instanceof TiViewProxy) { TiViewProxy viewProxy = (TiViewProxy) viewObject; this.view = viewProxy.getOrCreateView(); if (this.view == null) { Log.e(PROXY_NAME, "NO VIEW was created!!"); return; } Log.i(PROXY_NAME, "view: " + this.view.toString()); } } else return; if (args.containsKey("quality")) { this.quality = TiConvert.toInt(args.get("quality")); } if (args.containsKey("pageSize")) { Object pageSize = args.get("pageSize"); if (pageSize instanceof String) { if (pageSize.equals("letter")) { this.pageSize = PageSize.LETTER; } else if (pageSize.equals("A4")) { this.pageSize = PageSize.A4; } else { this.pageSize = PageSize.LETTER; } } } TiBaseFile file = TiFileFactory.createTitaniumFile(this.fileName, true); Log.i(PROXY_NAME, "file full path: " + file.nativePath()); try { Resources appResources = app.getResources(); OutputStream outputStream = file.getOutputStream(); final int MARGIN = 0; final float PDF_WIDTH = this.pageSize.getWidth() - MARGIN * 2; // A4: 595 //Letter: 612 final float PDF_HEIGHT = this.pageSize.getHeight() - MARGIN * 2; // A4: 842 //Letter: 792 final int DEFAULT_VIEW_WIDTH = 980; final int DEFAULT_VIEW_HEIGHT = 1384; int viewWidth = DEFAULT_VIEW_WIDTH; int viewHeight = DEFAULT_VIEW_HEIGHT; Document pdfDocument = new Document(this.pageSize, MARGIN, MARGIN, MARGIN, MARGIN); PdfWriter docWriter = PdfWriter.getInstance(pdfDocument, outputStream); Log.i(PROXY_NAME, "PDF_WIDTH: " + PDF_WIDTH); Log.i(PROXY_NAME, "PDF_HEIGHT: " + PDF_HEIGHT); WebView view = (WebView) this.view.getNativeView(); if (TiApplication.isUIThread()) { viewWidth = view.capturePicture().getWidth(); viewHeight = view.capturePicture().getHeight(); if (viewWidth <= 0) { viewWidth = DEFAULT_VIEW_WIDTH; } if (viewHeight <= 0) { viewHeight = DEFAULT_VIEW_HEIGHT; } } else { Log.e(PROXY_NAME, "NO UI THREAD"); viewWidth = DEFAULT_VIEW_WIDTH; viewHeight = DEFAULT_VIEW_HEIGHT; } view.setLayerType(View.LAYER_TYPE_SOFTWARE, null); Log.i(PROXY_NAME, "viewWidth: " + viewWidth); Log.i(PROXY_NAME, "viewHeight: " + viewHeight); float scaleFactorWidth = 1 / ((float) viewWidth / PDF_WIDTH); float scaleFactorHeight = 1 / ((float) viewHeight / PDF_HEIGHT); Log.i(PROXY_NAME, "scaleFactorWidth: " + scaleFactorWidth); Log.i(PROXY_NAME, "scaleFactorHeight: " + scaleFactorHeight); Bitmap viewBitmap = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888); Canvas viewCanvas = new Canvas(viewBitmap); // Paint paintAntialias = new Paint(); // paintAntialias.setAntiAlias(true); // paintAntialias.setFilterBitmap(true); Drawable bgDrawable = view.getBackground(); if (bgDrawable != null) { bgDrawable.draw(viewCanvas); } else { viewCanvas.drawColor(Color.WHITE); } view.draw(viewCanvas); TiBaseFile pdfImg = createTempFile(); // ByteArrayOutputStream stream = new ByteArrayOutputStream(32); // viewBitmap.compress(Bitmap.CompressFormat.JPEG, this.quality, stream); viewBitmap.compress(Bitmap.CompressFormat.JPEG, this.quality, pdfImg.getOutputStream()); FileInputStream pdfImgInputStream = new FileInputStream(pdfImg.getNativeFile()); byte[] pdfImgBytes = IOUtils.toByteArray(pdfImgInputStream); pdfImgInputStream.close(); // ByteBuffer buffer = ByteBuffer.allocate(viewBitmap.getByteCount()); // viewBitmap.copyPixelsToBuffer(buffer); pdfDocument.open(); float yFactor = viewHeight * scaleFactorWidth; int pageNumber = 1; do { if (pageNumber > 1) { pdfDocument.newPage(); } pageNumber++; yFactor -= PDF_HEIGHT; Image pageImage = Image.getInstance(pdfImgBytes, true); // Image pageImage = Image.getInstance(buffer.array()); pageImage.scalePercent(scaleFactorWidth * 100); pageImage.setAbsolutePosition(0f, -yFactor); pdfDocument.add(pageImage); Log.i(PROXY_NAME, "yFactor: " + yFactor); } while (yFactor > 0); pdfDocument.close(); sendCompleteEvent(); } catch (Exception exception) { Log.e(PROXY_NAME, "Error: " + exception.toString()); sendErrorEvent(exception.toString()); } }