how to fill color in image in particular area?

I found the Solution with Flood fill algoritham private void FloodFill(Bitmap bmp, Point pt, int targetColor, int replacementColor){ Queue<Point> q = new LinkedList<Point>(); q.add(pt); while (q.size() > 0) { Point n = q.poll(); if (bmp.getPixel(n.x, n.y) != targetColor) continue; Point w = n, e = new Point(n.x + 1, n.y); while ((w.x > 0) && … Read more

How to improve painting performance of DataGridView?

I recently had some slowness issues with DataGridView and the solution was the following code public static void DoubleBuffered(this DataGridView dgv, bool setting) { Type dgvType = dgv.GetType(); PropertyInfo pi = dgvType.GetProperty(“DoubleBuffered”, BindingFlags.Instance | BindingFlags.NonPublic); pi.SetValue(dgv, setting, null); } It turns double buffering on for DataGridView objects. Just call DoubleBuffered() on your DGV. Hope it … Read more

Images in paintComponent only show up after resizing the window

You need to call frame.pack() to do the initial layout. Resizing the window automatically causes the layout to be fixed, but frame.setSize(…) does not*. Move frame.setVisible(true) to the end of your run method (i.e. after you’ve constructed all the UI elements) and put frame.pack() just before frame.setVisible(true). (Thanks Hovercraft and MadProgrammer for pointing this out) … Read more

JLayeredPane and painting

As you found, a BufferedImage is an effective way to cache complex content for efficient rendering; CellTest is an example. A flyweight renderer, shown here, is another approach. Finally, I’ve re-factored your instructive example in a way that may make experimentation easier. import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import … Read more

Paint algorithm leaving white pixels at the edges when I color [duplicate]

You are using exact color fill for dithered/smoothed/antialiased/lossy_compressed image. That leaves pixels with even slightly different color uncolored (borders) creating artifacts. There are 2 easy ways how to remedy it: match close colors instead of exact if you got 2 RGB colors (r0,g0,b0) and (r1,g1,b1) right now (if I see it right) your checking is … Read more

how to convert rgb color to int in java

First of all, android.graphics.Color is a class thats composed of only static methods. How and why did you create a new android.graphics.Color object? (This is completely useless and the object itself stores no data) But anyways… I’m going to assume your using some object that actually stores data… A integer is composed of 4 bytes … Read more

How to get the pixel color on touch?

This is the one I’ve used, and it looks simpler than the methods you’ve tried. In my custom view class, I have this: – (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; CGPoint loc = [touch locationInView:self]; self.pickedColor = [self colorOfPoint:loc]; } colorOfPoint is a method in a category on UIView, with … Read more

Difference between paint() and paintcomponent()?

Quoting from documentation of paint() method This method actually delegates the work of painting to three protected methods: paintComponent, paintBorder, and paintChildren. … A subclass that just wants to specialize the UI (look and feel) delegate’s paint method should just override paintComponent. It looks like the paint() method actually draws the component, including the border … Read more

Drawing rectangle on a JPanel

1) for Swing JComponent you have to use paintComponent() instead of paint() method 2) your JComponent doesn’t returns PreferredSize for example import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.event.ComponentEvent; import javax.swing.JComponent; import javax.swing.JFrame; public class CustomComponent extends JFrame { private static final long serialVersionUID = 1L; public CustomComponent() { setTitle(“Custom Component Graphics2D”); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); … Read more

tech