Skip to main content

Posts

Showing posts with the label graphics

How to make glow effect around a bitmap?

The following code is what I got so far. However, there are 2 issues: I want both inner and outer glow effects, which looking similar to the Photoshop's blending options. But I only managed to make the outer glow, if I set BlurMaskFilter.Blur.INNER or other value, the whole image is blocked, instead of just edges. Despite I set "FF" as alpha value, the glow color is still very dark. Bitmap alpha = origin.extractAlpha(); BlurMaskFilter blurMaskFilter = new BlurMaskFilter(5, BlurMaskFilter.Blur.OUTER); Paint paint = new Paint(); paint.setMaskFilter(blurMaskFilter); paint.setColor(0xffffffff); Canvas canvas = new Canvas(origin); canvas.drawBitmap(alpha, 0, 0, paint); return origin; Source: Tips4all

Hit test on Graphics2D object?

I have a few Graphics2D objects (Line2D, Rectangle2D, Ellipse2D, Rectangle2D) and a GeneralPath. I know that if I want to hit test on them I could use the .contains(Point) method, but I need to hit test on these objects when they are not filled in. So I just want to test if the user clicked on their border/line. I don't need to worry about the thickness of the border for now. Let's say that I just need to worry if the user clicked within 10 pixels from the border/line. I do have a MouseListener where I can get the coordinates of the mouse click, and my Graphics2D objects are stored on a data structure that I iterate over. I just don't know how to hit test on the lines/borders. Any suggestions will be appreciated!

repaint() in Java

I write a Java code, but I have a trouble with GUI problem. When I add a component into JFrame object, then I call repaint() method in order to update the GUI but it doesn't work. But when I minimize or resize this frame, the GUI is updated. Here is my code: public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(460, 500); frame.setTitle("Circles generator"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); String input = JOptionPane.showInputDialog("Enter n:"); int n = Integer.parseInt(input); CircleComponent component = new CircleComponent(n); frame.add(component); component.repaint(); }

Drawing/warping a rectangular image into a quadrilateral image

I need to draw a BufferedImage within a given quadrilateral. I want to do that: I would like the cat to be deformed to be drawn within the quadrilateral. Graphics objects have different methods to draw images, but only to stretch them along the X and Y axis (See Graphics.drawImage methods). What I am dreaming of is a method Graphics.drawImage() where I specify the coordinates of the 4 quadrilateral points. Is there an easy way to do that?