Drawing an outer shadow when drawing an image

I wanted a similar effect, but on an AppWidget so unfortunately I couldn’t use @EvelioTarazona’s solution. This is what I came up with, it should work with a bitmap of any shape. final Bitmap src = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); final Bitmap shadow = addShadow(src, src.getHeight(), src.getWidth(), Color.BLACK, 3, 1, 3); final ImageView iv = (ImageView)findViewById(R.id.image); iv.setImageBitmap(shadow); … Read more

Android: How to check if a rectangle contains touched point?

Ok i solved my problem. I post the example code: Path p; Region r; @Override public void onDraw(Canvas canvas) { p = new Path(); p.moveTo(50, 50); p.lineTo(100, 50); p.lineTo(100, 100); p.lineTo(80, 100); p.close(); canvas.drawPath(p, paint); RectF rectF = new RectF(); p.computeBounds(rectF, true); r = new Region(); r.setPath(p, new Region((int) rectF.left, (int) rectF.top, (int) rectF.right, (int) … Read more

Android Canvas.drawText

Worked this out, turns out that android.R.color.black is not the same as Color.BLACK. Changed the code to: Paint paint = new Paint(); paint.setColor(Color.WHITE); paint.setStyle(Style.FILL); canvas.drawPaint(paint); paint.setColor(Color.BLACK); paint.setTextSize(20); canvas.drawText(“Some Text”, 10, 25, paint); and it all works fine now!!

MediaRecorder and VideoSource.SURFACE, stop failed: -1007 (a serious Android bug)

I guess there is no solution so the answer: MediaRecorder/Android is buggy or Mobile companies didn’t care of all Android features while developing their devices Update MediaCodec is also buggy with canvas mSurface = mMediaCodec.createInputSurface(); mSurface.lockHardwareCanvas() It works on much more devices with MediaCodec but still some devices may fail to record video correctly using … Read more

How to draw a filled triangle in android canvas?

Ok I’ve done it. I’m sharing this code in case someone else will need it: super.draw(canvas, mapView, true); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStrokeWidth(2); paint.setColor(android.graphics.Color.RED); paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setAntiAlias(true); Point point1_draw = new Point(); Point point2_draw = new Point(); Point point3_draw = new Point(); mapView.getProjection().toPixels(point1, point1_draw); mapView.getProjection().toPixels(point2, point2_draw); mapView.getProjection().toPixels(point3, point3_draw); Path path = new Path(); path.setFillType(Path.FillType.EVEN_ODD); path.moveTo(point1_draw.x,point1_draw.y); … Read more

Rotating Image on A canvas in android

You can either rotate your bitmap when you draw it by using a matrix: Matrix matrix = new Matrix(); matrix.setRotate(angle, imageCenterX, imageCenterY); yourCanvas.drawBitmap(yourBitmap, matrix, null); You can also do it by rotating the canvas before drawing: yourCanvas.save(Canvas.MATRIX_SAVE_FLAG); //Saving the canvas and later restoring it so only this image will be rotated. yourCanvas.rotate(-angle); yourCanvas.drawBitmap(yourBitmap, left, top, … Read more

Getting the pixel color value of a point on an Android View that includes a Bitmap-backed Canvas

How about load the view to a bitmap (at some point after all your drawing/sprites etc is done), then get the pixel color from the bitmap? public static Bitmap loadBitmapFromView(View v) { Bitmap b = Bitmap.createBitmap( v.getLayoutParams().width, v.getLayoutParams().height, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); v.layout(0, 0, v.getLayoutParams().width, v.getLayoutParams().height); v.draw(c); return b; } then use getPixel(x,y) … Read more