How to create a resizable rectangle with user touch events on Android?

Chintan Rathod’s answer was great solution but there are something wrong when He draws the rectangle. I just edit some lines of code to make it works correctly with user touch event. Now, you can add this view to your layout then touch to draw. import java.util.ArrayList; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; … Read more

Delphi – moving overlapping TShapes

A ‘simple sample redesign’ per my comment follows. unit Unit4; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs; const NUM_TRIANGLES = 10; COLORS: array[0..12] of integer = (clRed, clGreen, clBlue, clYellow, clFuchsia, clLime, clGray, clSilver, clBlack, clMaroon, clNavy, clSkyBlue, clMoneyGreen); type TTriangle = record X, Y: integer; // bottom-left corner Base, Height: … Read more

Image/Graphic into a Shape

motorcycle.jpg motorcycle-03.png ImageOutline.java This code requires some patience (when running). import java.awt.*; import java.awt.image.BufferedImage; import java.awt.geom.Area; import javax.imageio.ImageIO; import java.io.File; import java.util.Date; import javax.swing.*; /* Motorcycle image courtesy of ShutterStock http://www.shutterstock.com/pic-13585165/stock-vector-travel-motorcycle-silhouette.html */ class ImageOutline { public static Area getOutline(BufferedImage image, Color color, boolean include, int tolerance) { Area area = new Area(); for (int x=0; … Read more

Set android shape color programmatically

Note: Answer has been updated to cover the scenario where background is an instance of ColorDrawable. Thanks Tyler Pfaff, for pointing this out. The drawable is an oval and is the background of an ImageView Get the Drawable from imageView using getBackground(): Drawable background = imageView.getBackground(); Check against usual suspects: if (background instanceof ShapeDrawable) { … Read more