paint

how to fill color in image in particular area?

↘锁芯ラ 提交于 2019-11-27 03:28:41
I want to fill the color in white area for Paint based application so please give me suggestion for how to do this work.. Hardik Gajjar 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) && (bmp.getPixel(w.x, w.y) == targetColor)) { bmp.setPixel(w.x, w.y, replacementColor); if ((w.y > 0) && (bmp.getPixel(w.x,

MouseListener Help Java

独自空忆成欢 提交于 2019-11-27 02:24:34
I am trying to write a program in Java Swing that outputs a 10 x 10 grid of geometric rectangles filled with randoms colors. However, when the user clicks on one of the rectangles within the display window the rectangle should repaint() and change to another color. Thus far I have the rudimentary program running, but I can't figure out how to implement a mouseListener to it in order to have the rectangles' color change when a user clicks inside. At this point, the rectangles only repaint when the display window is expanded and minimized. Any advice/help would be greatly appreciated! Thanks!

Images in paintComponent only show up after resizing the window

若如初见. 提交于 2019-11-27 02:16:33
I want to use paintComponent(Graphics g) to paint a few images using a for loop. However, the JFrame just shows up as a white screen, and it only shows the black background and the images after I resize the window. import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import javax.imageio.*; import java.awt.geom.*; import java.awt.image.BufferedImage; import java.awt.Graphics; import java.util.Scanner; public class SimpleAdventure { private JFrame frame; private CardLayout cards; private Container c; private DrawPanel1 gamepanel; private BufferedImage greentiles,

how to convert rgb color to int in java

柔情痞子 提交于 2019-11-27 01:52:22
Paint.setColor is expecting an integer. But what I have is a Color object. I don't see a color.getIntValue() in Java? So how do I do that? What I want is something like public Something myMethod(Color rgb){ myPaint.setColor(rgb.getIntValue()); ... } Correction: android.graphics.Color; I thought having android as one of the tags would be enough. But apparently not. 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

Android Paint stroke width positioning

时光怂恿深爱的人放手 提交于 2019-11-27 01:51:06
问题 Given this code to draw a line: Paint p; p = new Paint(Paint.ANTI_ALIAS_FLAG); p.setColor(android.graphics.Color.WHITE); p.setStyle(Paint.Style.FILL); p.setStrokeWidth(21); canvas.drawLine(0,50,100,50,p); there are 3 possible stroke-drawing strategies: Inside: The line is painted in the rectangle (0,50,100,70) Center: The line is painted in the rectangle (0,40,100,60) Outside: The line is painted in the rectangle (0,30,100,50) In practice it appears that default behavior follows the Center

Drawing a filled rectangle with a border in android

自作多情 提交于 2019-11-27 01:27:08
问题 Is there any way in Android to draw a filled rectangle with say a black border. My problem is that the canvas.draw() takes one paint object, and to my knowledge the paint object can't have a different color for the fill and the stroke. Is there a way around this? 回答1: You draw a rectangle with the color of the border and the size of the rectangle plus the border, you change the color of the paint and draw again the rectangle with the normal size. 回答2: Try paint. setStyle (Paint.Style. FILL )

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

时光毁灭记忆、已成空白 提交于 2019-11-26 23:43:53
问题 This question already has an answer here: Canvas - floodfill leaves white pixels at edges 4 answers I am creating a drawing application. When I select a very dark color and paint inside the Panda's face, the edges are left white. I want my code to color entire area bound within the borders. This is the LINK. These are the functions that I am using in javascript. How can I make them better? function matchOutlineColor(r, g, b, a) { return (r + g + b < 75 && a >= 50); }; function matchStartColor

Draw / Paint Outside Form

≡放荡痞女 提交于 2019-11-26 23:30:12
问题 Can we paint images and draw text... outside a form.. i mean literally outside... i know its stupid question to ask but CAN we... 回答1: You can "cheat" by creating a form, and setting its TransparentColor property to its background color, then draw on it. However, this prohibits you from drawing the transparent color because it won't show. Or you could actually draw directly to the desktop. [DllImport("User32.dll")] public static extern IntPtr GetDC(IntPtr hwnd); [DllImport("User32.dll")]

Difference between paint() and paintcomponent()?

[亡魂溺海] 提交于 2019-11-26 22:58:54
I have tried tutorials on this but I still don't quite understand it. Basically my question is which method is better and why? Should I use paint or paintComponent ? Please try to keep the answer simple, thanks. christianhs 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

JApplet - super.paint(); causes flicker

做~自己de王妃 提交于 2019-11-26 22:13:22
问题 I'm writing a JApplet right now, and whenever I call super.paint(), the applet flickers. I am using double buffering (drawing to an image, and then rendering that image), but I think super.paint() is clearing the screen or something, defeating my double buffer. I know I'm supposed to use paintComponents(), but for some reason, when I call "currentScreen.Draw(g)," it won't show the screen's draw. Can anyone help me with this? public void paint(Graphics g) { super.paint(g);//Remove this and it