public void testDraw() { Bitmap bmp = Bitmap.createBitmap(9, 9, Config.ARGB_8888); Canvas c = new Canvas(bmp); int ocean = Color.rgb(0, 0xFF, 0x80); mNinePatchDrawable.setBounds(0, 0, 9, 9); mNinePatchDrawable.draw(c); assertColorFillRect(bmp, 0, 0, 4, 4, Color.RED); assertColorFillRect(bmp, 5, 0, 4, 4, Color.BLUE); assertColorFillRect(bmp, 0, 5, 4, 4, ocean); assertColorFillRect(bmp, 5, 5, 4, 4, Color.YELLOW); assertColorFillRect(bmp, 4, 0, 1, 9, Color.WHITE); assertColorFillRect(bmp, 0, 4, 9, 1, Color.WHITE); bmp.eraseColor(0xff000000); mNinePatchDrawable.setBounds(0, 0, 3, 3); mNinePatchDrawable.draw(c); assertColorFillRect(bmp, 0, 0, 1, 1, Color.RED); assertColorFillRect(bmp, 2, 0, 1, 1, Color.BLUE); assertColorFillRect(bmp, 0, 2, 1, 1, ocean); assertColorFillRect(bmp, 2, 2, 1, 1, Color.YELLOW); assertColorFillRect(bmp, 1, 0, 1, 3, Color.WHITE); assertColorFillRect(bmp, 0, 1, 3, 1, Color.WHITE); try { mNinePatchDrawable.draw(null); fail("The method should check whether the canvas is null."); } catch (NullPointerException e) { // expected } }
public static Bitmap capture( View view, float width, float height, boolean scroll, Bitmap.Config config) { if (!view.isDrawingCacheEnabled()) view.setDrawingCacheEnabled(true); Bitmap bitmap = Bitmap.createBitmap((int) width, (int) height, config); bitmap.eraseColor(Color.WHITE); Canvas canvas = new Canvas(bitmap); int left = view.getLeft(); int top = view.getTop(); if (scroll) { left = view.getScrollX(); top = view.getScrollY(); } int status = canvas.save(); canvas.translate(-left, -top); float scale = width / view.getWidth(); canvas.scale(scale, scale, left, top); view.draw(canvas); canvas.restoreToCount(status); Paint alphaPaint = new Paint(); alphaPaint.setColor(Color.TRANSPARENT); canvas.drawRect(0f, 0f, 1f, height, alphaPaint); canvas.drawRect(width - 1f, 0f, width, height, alphaPaint); canvas.drawRect(0f, 0f, width, 1f, alphaPaint); canvas.drawRect(0f, height - 1f, width, height, alphaPaint); canvas.setBitmap(null); return bitmap; }
public byte[] getTileImageData(int x, int y, int zoom) { mStream.reset(); Matrix matrix = new Matrix(mBaseMatrix); float scale = (float) (Math.pow(2, zoom) * mScale); matrix.postScale(scale, scale); matrix.postTranslate(-x * mDimension, -y * mDimension); mBitmap.eraseColor(Color.TRANSPARENT); Canvas c = new Canvas(mBitmap); c.setMatrix(matrix); // NOTE: Picture is not thread-safe. synchronized (mSvgPicture) { mSvgPicture.draw(c); } BufferedOutputStream stream = new BufferedOutputStream(mStream); mBitmap.compress(Bitmap.CompressFormat.PNG, 0, stream); try { stream.close(); } catch (IOException e) { Log.e(TAG, "Error while closing tile byte stream."); e.printStackTrace(); } return mStream.toByteArray(); }
private static android.graphics.Bitmap getTileBitmapFromReusableSet( int tileSize, boolean isTransparent) { int hash = composeHash(tileSize, isTransparent); Set<SoftReference<Bitmap>> subSet = reusableTileBitmaps.get(hash); if (subSet == null) { return null; } android.graphics.Bitmap bitmap = null; synchronized (subSet) { final Iterator<SoftReference<android.graphics.Bitmap>> iterator = subSet.iterator(); android.graphics.Bitmap candidate; while (iterator.hasNext()) { candidate = iterator.next().get(); if (null != candidate && candidate.isMutable()) { bitmap = candidate; if (isTransparent) { bitmap.eraseColor(android.graphics.Color.TRANSPARENT); } // Remove from reusable set so it can't be used again. iterator.remove(); break; } else { // Remove from the set if the reference has been cleared. iterator.remove(); } } } return bitmap; }
@Override public void drawData(Canvas c) { int width = (int) mViewPortHandler.getChartWidth(); int height = (int) mViewPortHandler.getChartHeight(); if (mDrawBitmap == null || (mDrawBitmap.getWidth() != width) || (mDrawBitmap.getHeight() != height)) { if (width > 0 && height > 0) { mDrawBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444); mBitmapCanvas = new Canvas(mDrawBitmap); } else return; } mDrawBitmap.eraseColor(Color.TRANSPARENT); PieData pieData = mChart.getData(); for (PieDataSet set : pieData.getDataSets()) { if (set.isVisible() && set.getEntryCount() > 0) drawDataSet(c, set); } }
public void buildCache(int w, int h, int density, boolean checkSizeEquals) { boolean reuse = checkSizeEquals ? (w == width && h == height) : (w <= width && h <= height); if (reuse && bitmap != null && !bitmap.isRecycled()) { // canvas.drawColor(Color.TRANSPARENT); canvas.setBitmap(null); bitmap.eraseColor(Color.TRANSPARENT); canvas.setBitmap(bitmap); recycleBitmapArray(); return; } if (bitmap != null) { recycle(); } width = w; height = h; bitmap = NativeBitmapFactory.createBitmap(w, h, Bitmap.Config.ARGB_8888); if (density > 0) { mDensity = density; bitmap.setDensity(density); } if (canvas == null) { canvas = new Canvas(bitmap); canvas.setDensity(density); } else canvas.setBitmap(bitmap); }
public void setForeBitmap(Bitmap forebitmap) { if (bitmap != null) { bitmap.eraseColor(0); } if (forebitmap != null) paper.drawBitmap(forebitmap, 0, 0, null); invalidate(); }
private void drawIntoBitmap() { Paint p = new Paint(Paint.ANTI_ALIAS_FLAG); if (mAlpha) { if (!mBlur) { mViewBitmap.eraseColor(Color.TRANSPARENT); } } if (mBlur) { if (mAlphaMark) { p.setAlpha(mBlurVal); } else { mAlphaMark = true; } } Canvas c = new Canvas(mViewBitmap); c.save(); Path path = new Path(); path.moveTo(0, 0); path.arcTo( new RectF(-mBitmapViewWidth, -mBitmapViewWidth, mBitmapViewWidth, mBitmapViewWidth), 0, mAngle); // path.lineTo(0, 1); path.close(); c.clipPath(path); // c.drawRGB(0, 0, 0); // RectF r = new RectF(0, 0, mBitmapViewWidth, mBitmapViewHeight); c.drawBitmap( mBitmap, new Rect(mCurX, mCurY, mRadius + mCurX, mBitmapNewHeight + mCurY), new RectF(0, 0, mBitmapViewWidth, mBitmapViewHeight), p); }
private void regenInRunnable() { Bitmap bmp = mRegenBitmap != null ? mRegenBitmap : mCachedBitmap; int count = -1; try { synchronized (bmp) { bmp.eraseColor(mBkColor); count = drawShapes(new Canvas(bmp), mCanvasRegen, false); if (bmp == mRegenBitmap) { if (mCachedBitmap != null) { mCachedBitmap.recycle(); } mCachedBitmap = mRegenBitmap; } } if (!mCoreView.isStopping()) { postInvalidate(); } } catch (Exception e) { Log.w(TAG, "Fail to draw on the cached bitmap", e); } mRegenBitmap = null; mRegenning = false; if (count >= 0 && !mCoreView.isStopping()) { mViewAdapter.onFirstRegen(); } }
private void updateHUD() { // TODO Line wrap! HUD.eraseColor(Color.TRANSPARENT); float textHeight = paint.getFontSpacing(); int rowsOnScreen = (int) (hudHeight / textHeight); float baseLine = hudHeight - Math.max(0, rowsOnScreen - lines.size()) * textHeight; log( "updateHUD", "textHeight = %.2f, rowsOnScreen = %d, lines.size() = %d, baseLine = %.2f", textHeight, rowsOnScreen, lines.size(), baseLine); int written = 0; for (String line : lines) { canvas.drawText(line, textXOffset, baseLine - textHeight + textYOffset, paint); written += 1; baseLine -= textHeight; if (baseLine < textHeight) { break; } } for (int index = lines.size() - 1; index > written; --index) { lines.remove(index); } setMainTexture(); }
private Bitmap drawTextToBitmap(String gText) { Bitmap bitmap = Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888); bitmap.eraseColor(Color.TRANSPARENT); bitmap.setHasAlpha(true); // bitmap.setHasAlpha(true); Canvas canvas = new Canvas(bitmap); canvas.drawColor(Color.TRANSPARENT); TextPaint textPaint = new TextPaint(); textPaint.setColor(Color.GREEN); textPaint.setTextSize(35); RectF rect = new RectF(0, 0, 300, 300); StaticLayout sl = new StaticLayout( gText, textPaint, (int) rect.width(), Layout.Alignment.ALIGN_NORMAL, 1, 1, false); canvas.save(); sl.draw(canvas); canvas.restore(); // Flip the image. Matrix m = new Matrix(); m.preScale(-1, 1); Bitmap output = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, false); output.setDensity(DisplayMetrics.DENSITY_DEFAULT); return output; }
private void drawBlurBackground(Canvas canvas) { if (mBlurredView != null) { if (prepare()) { if (mBlurredBackgroundColor != 0) { mBitmapToBlur.eraseColor(mBlurredBackgroundColor); } mBlurredView.draw(mBlurringCanvas); blur(); NiceTabLayout tabLayout = (NiceTabLayout) getParent(); if (tabLayout != null) { final int pPaddingLeft = tabLayout.getPaddingLeft(); final int pPaddingRight = tabLayout.getPaddingRight(); canvas.save(); if (tabLayout.getPaddingLeft() != 0 || tabLayout.getPaddingRight() != 0) { // allow drawing out of bounds Rect clipBounds = canvas.getClipBounds(); clipBounds.inset(-(pPaddingLeft + pPaddingRight), 0); canvas.clipRect(clipBounds, Region.Op.REPLACE); } canvas.translate( mBlurredView.getLeft() - getLeft() + tabLayout.getScrollX(), mBlurredView.getTop() - getTop()); canvas.scale(mDownSampleFactor, mDownSampleFactor); canvas.drawBitmap(mBlurredBitmap, 0, 0, null); canvas.drawColor(mOverlayColor); canvas.restore(); } } } }
private void init(Context mContext) { if (arrowResource != 0) { arrowBitmap = BitmapFactory.decodeResource(mContext.getResources(), arrowResource); canvasBitmap = arrowBitmap.copy(Bitmap.Config.ARGB_4444, true); canvasBitmap.eraseColor(0x00000000); paint = new Paint(); } }
static int CreateTxtTexture( String txt, Typeface typeface, float font_size, boolean align_center) { Paint textPaint = new Paint(); textPaint.setTypeface(typeface); textPaint.setTextSize(font_size); textPaint.setTextAlign(align_center ? Paint.Align.CENTER : Paint.Align.LEFT); textPaint.setAntiAlias(true); textPaint.setARGB(0xff, 0xFF, 0xFF, 0xFF); int width = 0; int height = 0; int line_height = (int) Math.ceil(-textPaint.ascent() + textPaint.descent()); String[] lines = txt.split("\n"); for (String line : lines) { int line_width = (int) Math.ceil(textPaint.measureText(line)); if (line_width > width) width = line_width; height += line_height; } int power2_width = Integer.highestOneBit(width); if (power2_width < width) power2_width = power2_width << 1; int power2_height = Integer.highestOneBit(height); if (power2_height < height) power2_height = power2_height << 1; // Log.i(TAG, "CreateTxtTexture calculate w " + width + " h " + height + // " power2 w " + power2_width + " h " + power2_height); if (0 == power2_width || 0 == power2_height) return 0; Bitmap bitmap = Bitmap.createBitmap(power2_width, power2_height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); bitmap.eraseColor(0); float origin_x = align_center ? (width / 2) : 0; float origin_y = -textPaint.ascent(); for (String line : lines) { canvas.drawText(line, origin_x, origin_y, textPaint); origin_y += line_height; } // canvas.setBitmap(null); // Log.i(TAG, "CreateTxtTexture " + txt + " use " + font_name + " " + font_size); // Use the Android GLUtils to specify a two-dimensional texture image // from our bitmap GLUtils.texImage2D(GL11.GL_TEXTURE_2D, 0, bitmap, 0); // bitmap.recycle(); return width + (height << 16); }
@Override public void drawGhost(Canvas canvas) { if (ghostBitmap != null) { ghostBitmap.eraseColor(indexColor); canvas.drawBitmap(ghostBitmap, drawingMatrix, null); } else { canvas.drawPath(ghostPath, ghostPaint); } }
public void clearCanvas() { if (bitmap != null) { bitmap.recycle(); bitmap = null; bitmap = Bitmap.createBitmap(PAPER_WIDTH, PAPER_HEIGHT, Bitmap.Config.ARGB_4444); bitmap.eraseColor(0); paper = new Canvas(bitmap); } invalidate(); }
@Override public void onCreate(SurfaceHolder holder) { super.onCreate(holder); mBackgroundBitmap = Bitmap.createBitmap(320, 320, Bitmap.Config.RGB_565); mBackgroundBitmap.eraseColor(Color.BLACK); mPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)); mPaint.setTextSize(20f); mPaint.setColor(Color.BLUE); }
@Override public Bitmap snapshot(int doc, int gs, boolean transparent) { final Bitmap bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888); final CanvasAdapter canvasAdapter = new CanvasAdapter(this, mImageCache); final Longs docs = new Longs(doc, 0); bitmap.eraseColor(transparent ? Color.TRANSPARENT : mBkColor); int n = drawShapes(docs, gs, null, new Canvas(bitmap), canvasAdapter, false); Log.d(TAG, "snapshot(doc): " + n); canvasAdapter.delete(); return bitmap; }
@Override protected void onDraw(Canvas canvas) { // if (y > -50) { // y--; // } // 采用三阶贝塞尔 不停地改变X 模拟水波效果 if (x > 50) { isLeft = true; } else if (x < 0) { isLeft = false; } if (isLeft) { x = x - 1; } else { x = x + 1; } mPath.reset(); y = (int) ((1 - mPercent / 100f) * mHeight); // 设置起点 mPath.moveTo(0, y); // 画二阶贝塞尔曲线,前两个为辅助坐标点 第三个点为终点 mPath.cubicTo(100 + x * 2, 50 + y, 100 + x * 2, y - 50, mWidth, y); mPath.lineTo(mWidth, mHeight); // 充满整个画布 mPath.lineTo(0, mHeight); // 充满整个画布 mPath.close(); // 清除掉图像 不然path会重叠 mBitmap.eraseColor(Color.parseColor("#00000000")); // dst // mCanvas.drawBitmap(bgBitmap,0,0,null); // mSRCPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); mCanvas.drawCircle(mWidth / 2, mHeight / 2, mWidth / 2, mSRCPaint); mWavePaint.setXfermode(mMode); // src mCanvas.drawPath(mPath, mWavePaint); mWavePaint.setXfermode(null); // 清空mBitmap,不然path会重叠 canvas.drawBitmap(mBitmap, 0, 0, null); String str = mPercent + ""; mTextPaint.setTextSize(80); float txtLength = mTextPaint.measureText(str); canvas.drawText(str, mWidth / 2 - txtLength / 2, mHeight / 2 + 15, mTextPaint); mTextPaint.setTextSize(40); canvas.drawText("%", mWidth / 2 + 50, mHeight / 2 - 20, mTextPaint); postInvalidateDelayed(10); }
@Override public synchronized Bitmap get(int width, int height, Bitmap.Config config) { Bitmap result = getDirty(width, height, config); if (result != null) { // Bitmaps in the pool contain random data that in some cases must be cleared for an image to // be rendered // correctly. we shouldn't force all consumers to independently erase the contents // individually, so we do so // here. See issue #131. result.eraseColor(Color.TRANSPARENT); } return result; }
public HandDraw(View v) { view = v; try { bitmapSrc = Bitmap.createBitmap( GlobalVariables.screenWidth, GlobalVariables.canvasHeigh, Bitmap.Config.ARGB_4444); bitmapSrc.eraseColor(0x0); canvasSrc = new Canvas(bitmapSrc); bitmapDst = Bitmap.createBitmap( GlobalVariables.screenWidth, GlobalVariables.canvasHeigh, Bitmap.Config.ARGB_4444); bitmapDst.eraseColor(0x0); canvasDst = new Canvas(bitmapDst); DrawingFactory factory = new DrawingFactory(); pathDrawing = (PathLine) factory.createDrawing(DrawingId.DRAWING_PATHLINE, null); Paint paint = new Paint(); paint = Brush.getPen(); pathDrawing.setPen(paint); canvasSrc.setDrawFilter(new PaintFlagsDrawFilter(0x0, 0x3)); } catch (OutOfMemoryError e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } // 笔迹颜色 path = new Path(); int colll = Brush.getPen().getColor(); thinPen.setColor(colll); thinPen.setStrokeWidth(1.5f); thinPen.setAntiAlias(true); thinPen.setDither(true); thinPen.setStyle(Paint.Style.STROKE); thinPen.setStrokeJoin(Paint.Join.ROUND); thinPen.setStrokeCap(Paint.Cap.ROUND); }
/** * Snapshot a view into a Bitmap with the indicated background color. * * @param view The target {@link android.view.View}. * @param backgroundColor The background color of the Bitmap. If the view has transparency areas, * these areas will be erased using this color. * @return Returns a Bitmap containing the view content, or {@code null} if any error occurs. Make * sure to call {@link android.graphics.Bitmap#recycle()} as soon as possible, once its * content is not needed anymore. */ public Bitmap snapshotView(View view, int backgroundColor) { if (view == null) { return null; } int viewWidth = view.getRight() - view.getLeft(); int viewHeight = view.getBottom() - view.getTop(); int sampleWidth = viewWidth / mSampleSize; int sampleHeight = viewHeight / mSampleSize; float canvasScale = 1.f / mSampleSize; sampleWidth = sampleWidth > 0 ? sampleWidth : 1; sampleHeight = sampleHeight > 0 ? sampleHeight : 1; performanceTickBegin( "snapshotView " + view + " sampleSize = " + mSampleSize + " (" + sampleWidth + ", " + sampleHeight + "): "); Bitmap bitmap = Bitmap.createBitmap(sampleWidth, sampleHeight, Bitmap.Config.ARGB_8888); if (bitmap == null) { throw new OutOfMemoryError(); } if ((backgroundColor & 0xff000000) != 0) { bitmap.eraseColor(backgroundColor); } bitmap.setDensity(mDisplayMetrics.densityDpi); Canvas canvas = new Canvas(bitmap); canvas.scale(view.getScaleX() * canvasScale, view.getScaleY() * canvasScale); canvas.translate(-view.getScrollX(), -view.getScrollY()); view.computeScroll(); view.draw(canvas); canvas.setBitmap(null); performanceTickEnd(); return bitmap; }
private Bitmap loadBitmap(int width, int height, int index) { Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444); bitmap.eraseColor(0xFF00FFFF); Canvas canvas = new Canvas(bitmap); Paint p = new Paint(); p.setColor(0xFF000000); p.setTextSize(200.0f); canvas.drawText(Integer.valueOf(index).toString(), 400, 400, p); canvas.drawRect(10, 10, 300, 300, p); return bitmap; }
private void createText(List<Ball> ballsArrayList, String text) { int w = (width / step) * step; int h = (height / step) * step; bitmap = Bitmap.createBitmap(w, h, Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setColor(Color.WHITE); paint.setTextSize((int) (h * 0.5)); paint.setFakeBoldText(true); paint.setAntiAlias(true); paint.setTextAlign(Paint.Align.CENTER); bitmap.eraseColor(Color.BLACK); canvas.drawText(text, w / 2, (int) (h * 0.6), paint); int pix[] = new int[w * h]; bitmap.getPixels(pix, 0, w, 0, 0, w, h); float s = 1.2f; float[] hsv = new float[3]; int midx = w / 2, midy = h / 2; for (int y = 0; y < h; y += step) { for (int x = 0; x < w; x += step) { int offset = x + y * w; long sum = 0; for (int dy = 0; dy < step; dy++) { for (int dx = 0; dx < step; dx++) { sum += (pix[offset + dx + dy * w] & 0xff); } } sum = sum / (step * step); int radius = (int) (step * sum / 255); if (radius > 1) { hsv[0] = 360 * x / width; hsv[1] = 1; hsv[2] = 1; ballsArrayList.add( new Ball( s * (x - midx) + midx, s * (y - midy) + midy, 0, radius, Color.HSVToColor(hsv))); } } } bitmap = null; }
public void updateBackground() { if (getWidth() == 0 || getHeight() == 0) { return; } Bitmap background = Bitmap.createBitmap(getWidth(), getHeight(), Config.ARGB_8888); background.eraseColor(ColorPickerDialog.mNewColor); Canvas checkerdBackgroundCanvas = new Canvas(background); Rect colorRect = new Rect(0, 0, getWidth(), getHeight()); if (ColorPickerDialog.mBackgroundPaint != null) { checkerdBackgroundCanvas.drawRect(colorRect, ColorPickerDialog.mBackgroundPaint); } mColorPaint.setColor(ColorPickerDialog.mNewColor); checkerdBackgroundCanvas.drawPaint(mColorPaint); setBackgroundDrawable(new BitmapDrawable(background)); }
protected void draw_mode(int mode) { Log.e("navit", "draw_mode " + mode); if (mode == 2 && parent_graphics == null) { view.draw(draw_canvas); view.invalidate(); view.requestRender(); } if (mode == 1 || (mode == 0 && parent_graphics != null)) { if (renderer != null) { renderer.flb_len = 0; } draw_bitmap.eraseColor(0); } if (mode == 0 && renderer != null) { renderer.flb_len = 0; } }
@Override public Bitmap snapshot(boolean transparent) { if (mCachedBitmap != null && transparent == (mBkColor == Color.TRANSPARENT)) { synchronized (mCachedBitmap) { return mCachedBitmap.copy(Config.ARGB_8888, false); } } final Bitmap bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888); final CanvasAdapter canvasAdapter = new CanvasAdapter(this, mImageCache); bitmap.eraseColor(transparent ? Color.TRANSPARENT : mBkColor); int n = drawShapes(new Canvas(bitmap), canvasAdapter, false); Log.d(TAG, "snapshot: " + n); canvasAdapter.delete(); return bitmap; }
public static SmartTexture createSolid(int color) { String key = "1x1:" + color; if (all.containsKey(key)) { return all.get(key); } else { Bitmap bmp = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); bmp.eraseColor(color); SmartTexture tx = new SmartTexture(bmp); all.put(key, tx); return tx; } }
private void interestingThumbnail(Bitmap image) { // image into OpenCV Mat imageMat = new Mat(); bitmapToMat(image, imageMat); // find slice of interest /*Mat rowSums = new Mat(imageMat.height(), 1, CvType.CV_16U); for(int y = (int)(0.1*image.getHeight()); y < image.getHeight(); y++) { Mat row = new Mat(imageMat, new Rect(0, 0, imageMat.width(), imageMat.height())); rowSums.put(y, 1, (int)Core.sumElems(row).val[0]); } final int binSize = 32; double current = 0; int startPos = 0; for(int y = 0; y < rowSums.cols() - binSize; y++) { Mat binned = new Mat(rowSums, new Rect(y, 0, binSize, 1)); double average = Core.sumElems(binned).val[0] / binSize; if(average > current) startPos = y; current = average; } // ensure not out of bounds if(startPos > imageMat.height() - binSize) startPos = imageMat.height() - binSize; // get slice of interest Rect roi = new Rect(0, startPos, imageMat.width(), binSize); Mat croppedRef = new Mat(imageMat, roi); Mat croppedMat = new Mat(croppedRef.width(), croppedRef.height(), croppedRef.type()); croppedRef.copyTo(croppedMat);*/ // image out of OpenCV // thumbnail = Bitmap.createBitmap(roi.width, roi.height, image.getConfig()); thumbnail = Bitmap.createBitmap(imageMat.width(), 64, image.getConfig()); thumbnail.eraseColor( Color.argb( 255, (int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255))); // matToBitmap(croppedRef, thumbnail); }
public BitmapDrawable rotateDrawable(float angle) { Bitmap arrowBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.location_arrow); // Create blank bitmap of equal size Bitmap canvasBitmap = arrowBitmap.copy(Bitmap.Config.ARGB_8888, true); canvasBitmap.eraseColor(0x00000000); // Create canvas Canvas canvas = new Canvas(canvasBitmap); // Create rotation matrix Matrix rotateMatrix = new Matrix(); rotateMatrix.setRotate(angle, canvas.getWidth() / 2, canvas.getHeight() / 2); // Draw bitmap onto canvas using matrix canvas.drawBitmap(arrowBitmap, rotateMatrix, null); return new BitmapDrawable(canvasBitmap); }