paint

android set custom font to a paint

自古美人都是妖i 提交于 2019-11-26 12:06:35
问题 I want to draw a text to a paint. How to draw it with a custom font ( ex Helvetica ) and bold also? I would preffer to use a system font and not create it from assets. Thanks. 回答1: If by "custom font" you mean a font that you are supplying as an asset, the following code should work: Typeface plain = Typeface.createFromAsset(assetManager, pathToFont); Typeface bold = Typeface.create(plain, Typeface.DEFAULT_BOLD) Paint paint = new Paint(); paint.setTypeface(bold); canvas.drawText("Sample text

Dynamic Graphics Object Painting

淺唱寂寞╮ 提交于 2019-11-26 11:53:56
Trying to figure out the best way to do this (And without crossing any specifics DO NOTs that I don't know about). I'm working on visually displaying a graph (Various nodes, with edges connecting them) with circles and lines to represent such. Each node will be added during runtime and I can't hardcode this. From what I understand, all painting needs to be done in the paint(Graphics g) method - which isn't that helpful, since I can't be change the parameters and it seems this is only called during the initial creation? Right now I was thinking about having it call various other methods,

JLayeredPane and painting

瘦欲@ 提交于 2019-11-26 11:32:14
问题 I am writing an application which has a JLayeredPane (call it layers) containing two JPanels in different layers. I override the paintComponent method of the JPanel at the bottom (call it grid_panel) so it paints a grid, and the the paintComponent method of the one at the top (call it circuit_panel) so it paints a circuit. Here\'s a summary of the structure: layers - |-circuit_panel (on top) |-grid_panel (at bottom) I want the grid_panel to stay static, ie, not to do any repaint (except the

how to fill color in image in particular area?

99封情书 提交于 2019-11-26 10:29: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.. 回答1: 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) ==

Images in paintComponent only show up after resizing the window

岁酱吖の 提交于 2019-11-26 10:04:52
问题 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

MouseListener Help Java

折月煮酒 提交于 2019-11-26 10:02:56
问题 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

how to convert rgb color to int in java

£可爱£侵袭症+ 提交于 2019-11-26 09:47:56
问题 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. 回答1: First of all, android.graphics.Color is a class thats composed of only static methods. How and why did you create a new

Difference between paint() and paintcomponent()?

假如想象 提交于 2019-11-26 08:30:27
问题 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. 回答1: 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

Problems with Java&#39;s Paint method, ridiculous refresh velocity

て烟熏妆下的殇ゞ 提交于 2019-11-26 07:49:28
问题 I\'m developing a very simple version of R-Type as work for the university, but despite it works, the craft velocity is a lot of slow, so the movement is ugly and clumsy. I use the method repaint for refresh the screen, there are others methods or ways best than it? Video of Movement Paint method at main Panel @Override public void paint(Graphics g) { super.paint(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2

How to get the pixel color on touch?

烈酒焚心 提交于 2019-11-26 07:24:36
问题 I know this is a common question and there are a lot of answers of this question. I\'ve used some of this. Although many of them are the same. But the sad thing for me is that none of them worked for me. The following codes i\'ve used till now. -(void)getRGBAsFromImage:(UIImage*)image atX:(int)xx andY:(int)yy { // First get the image into your data buffer CGImageRef imageRef = [image CGImage]; NSUInteger width = CGImageGetWidth(imageRef); NSUInteger height = CGImageGetHeight(imageRef);