How to draw curved and straight lines in one image?


stack

I'm trying to draw a rectangle that is basically a circle, with a square on one end. Kind of like a battery. I have some limitations, basically this can only be done with a single paint object and should be able to support strokes.

Here is my code so far:

int width = 0;
int height = 0;

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    // myPath outline
    Point[] myPath = { new Point(20, 20), new Point(width, 20), new Point(width, height), new Point(20, height),
            new Point(20, height - 20), new Point(0, height - 20), new Point(0, height - 40),
            new Point(20, height - 40) };

    // Paint
    Paint paint = new Paint();
    int color = 0xffff0000;
    paint.setColor(color);
    paint.setAntiAlias(true);
    // paint.setPathEffect(new CornerPathEffect(15));
    paint.setStyle(Paint.Style.FILL);

    // Path moves
    Path path = new Path();

    path.moveTo(myPath[0].x, myPath[0].y);
    int j = myPath.length;
    for (int i = 0; i < j; i++) {
        path.lineTo(myPath[i].x, myPath[i].y);
    }
    path.close();

    Bitmap toDrawOn;
    toDrawOn = Bitmap.createBitmap(getWidth(), getHeight(), Config.ARGB_8888);
    Canvas ofScreen = new Canvas(toDrawOn);
    ofScreen.drawPath(path, paint);
    canvas.drawBitmap(toDrawOn, 0, 0, paint);

}

This gives me the desired shape of the cell, but I don't know how to round the first four corners without making the last four corners of the small square. Again, I need to make this shape a shape because I need to stroke it later. I also can't use 9patch because I need to change the color programmatically.

Here is my goal:

enter image description here

ug_

use path.quadTo (using javadoc) . Because this shape is so simple, I'll write it line by line. This is the beginning of it.

int borderRadius = 15;
Path path = new Path();
path.moveTo(borderRadius , 0);
path.lineTo(width-borderRadius, 0); // top side
path.quadTo(width, 0, width, borderRadius); // top right corner
path.lineTo(width, height-borderRadius); // right side
path.quadTo(width, height, width-borderRadius, height); // bottom right corner
...
path.close();

Related


How to draw curved and straight lines in one image?

stack I'm trying to draw a rectangle that is basically a circle, with a square on one end. Kind of like a battery. I have some limitations, basically this can only be done with a single paint object and should be able to support strokes. Here is my code so far

How to draw "curved" lines?

Daniel The problem is simple, as the title says. Tizen's documentation is really unreliable on this topic (among others). For example, as they describe here : Draw SVG paths. You can use the api in efl_gfx_utils.h to construct the path ... efl_gfx_path_append_

How to draw "curved" lines?

Daniel The problem is simple, as the title says. Tizen's documentation is really unreliable on this topic (among others). For example, as they describe here : Draw SVG paths. You can use the api in efl_gfx_utils.h to construct the path ... efl_gfx_path_append_

How to draw straight lines with JUNG2?

frank After testing with JUNG2, I found that all edge lines are curved, but not straight... How to do straight line of edge through Jung2? package pkg; import javax.swing.JFrame; import edu.uci.ics.jung.algorithms.layout.CircleLayout; import edu.uci.ics.jung

How to draw straight lines using ZingChart?

Olavi Sau The final result should look like this. See the LSL line? How can I draw, is there a way to force the first value to draw? Or should I draw an overlay? try (internal series) valueBox:{ visible:true, color:"red", text:"LPL" }, type:'line',

How to draw a curve from multiple straight lines?

Come on, GhahremanNezhad I am trying to connect some straight lines to form a curve. For example, if I have three lines like this : I want to draw a curve like this: I try to use OpenCV line and polyline functions. for (size_t i = 0;i < lines.size();i++)

How to draw straight lines with JUNG2?

frank After testing with JUNG2, I found that all edge lines are curved, but not straight... How to do straight line of edge through Jung2? package pkg; import javax.swing.JFrame; import edu.uci.ics.jung.algorithms.layout.CircleLayout; import edu.uci.ics.jung

How to draw straight lines with JUNG2?

frank After testing with JUNG2, I found that all edge lines are curved, but not straight... How to do straight line of edge through Jung2? package pkg; import javax.swing.JFrame; import edu.uci.ics.jung.algorithms.layout.CircleLayout; import edu.uci.ics.jung

How to draw a curve from multiple straight lines?

Come on, GhahremanNezhad I am trying to connect some straight lines to form a curve. For example, if I have three lines like this : I want to draw a curve like this: I try to use OpenCV line and polyline functions. for (size_t i = 0;i < lines.size();i++)

How to draw straight lines with JUNG2?

frank After testing with JUNG2, I found that all edge lines are curved, but not straight... How to do straight line of edge through Jung2? package pkg; import javax.swing.JFrame; import edu.uci.ics.jung.algorithms.layout.CircleLayout; import edu.uci.ics.jung

How to draw a rectangle with one side curved in html

Langjak Is it possible to draw a rectangle and bend the top in html? The shape should appear at the bottom of the html page, which is required for the footer. Maroon Crossing Try this: this should only show the first step :-) .wrapper { width: 500px; heigh

How to remove straight lines from Matlab image?

Sack 11 I have a matlab image from a matrix as shown below.Two_dim I want to remove all 3 bottom horizontal lines from the image . I looked at Stackoverflow to regionpropsremove horizontal lines and got this code. But that doesn't seem to remove any limitation

How to remove straight lines from Matlab image?

Sack 11 I have a matlab image from a matrix as shown below.Two_dim I want to remove all 3 bottom horizontal lines from the image . I looked at Stackoverflow to regionpropsremove horizontal lines and got this code. But that doesn't seem to remove any limitation

How to remove straight lines from Matlab image?

Sack 11 I have a matlab image from a matrix as shown below.Two_dim I want to remove all 3 bottom horizontal lines from the image . I looked at Stackoverflow to regionpropsremove horizontal lines and got this code. But that doesn't seem to remove any limitation

How to remove straight lines from Matlab image?

Sack 11 I have a matlab image from a matrix as shown below.Two_dim I want to remove all 3 bottom horizontal lines from the image . I looked at Stackoverflow to regionpropsremove horizontal lines and got this code. But that doesn't seem to remove any limitation

How to smooth jagged edges of an image into straight lines?

aspiring_sarge I have an image like this (thresholding, noise removal etc done): My final output should be an image without any jagged edges and smaller than the given image. By this, I mean to say that the only difference between the two images must be that i

How to remove straight lines from Matlab image?

Sack 11 I have a matlab image from a matrix as shown below.Two_dim I want to remove all 3 bottom horizontal lines from the image . I looked at Stackoverflow to regionpropsremove horizontal lines and got this code. But that doesn't seem to remove any limitation

How to remove straight lines from Matlab image?

Sack 11 I have a matlab image from a matrix as shown below.Two_dim I want to remove all 3 bottom horizontal lines from the image . I looked at Stackoverflow to regionpropsremove horizontal lines and got this code. But that doesn't seem to remove any limitation

How to draw straight lines (horizontal and vertical) in d3.js

Divaca I have a question about drawing a line chart concept. Can anyone explain these coordinates? x1=5,x2=10,y1=10,y2=30 Please explain each attribute and what it represents. Also, please give me an idea about drawing a straight line (like a crosshair) both v

How to draw straight lines (horizontal and vertical) in d3.js

Divaca I have a question about drawing a line chart concept. Can anyone explain these coordinates? x1=5,x2=10,y1=10,y2=30 Please explain each attribute and what it represents. Also, please give me an idea about drawing a straight line (like a crosshair) both v

How to draw straight lines (horizontal and vertical) in d3.js

Divaca I have a question about drawing a line chart concept. Can anyone explain these coordinates? x1=5,x2=10,y1=10,y2=30 Please explain each attribute and what it represents. Also, please give me an idea about drawing a straight line (like a crosshair) both v

How to draw straight lines in d3.js with user interaction

Divaca I want to draw line based on user's click. That is, the user will click a start somewhere and an end point somewhere, and I want to draw a line between those points. Anyway, in d3.js it is possible to do this. Is it possible? Tanush Yes, you can draw li

How to draw straight lines in d3.js with user interaction

Divaca I want to draw line based on user's click. That is, the user will click a start somewhere and an end point somewhere, and I want to draw a line between those points. Anyway, in d3.js it is possible to do this. Is it possible? Tanush Yes, you can draw li

How to draw straight lines (horizontal and vertical) in d3.js

Divaca I have a question about drawing a line chart concept. Can anyone explain these coordinates? x1=5,x2=10,y1=10,y2=30 Please explain each attribute and what it represents. Also, please give me an idea about drawing a straight line (like a crosshair) both v

How to draw curved shadows?

Ilutov like this: I know this doesn't work NSShadow, drawRect:plugging it in does the trick. David Rönnqvist You can use Core Animations layers and shadowPathproperties to do this and many other types of shadows . The shadow you describe can be generated by an

How to draw lines on an image in OpenCV?

Rahul: If I have polar coordinates of a line, how can I draw it on an image in OpenCV and python? LineThe function takes 2 points, but only draws line segments. I want to draw a line from one edge of an image to the other. Robert Caspary: Just count 2 points.

How to draw lines on an image in OpenCV?

Rahul: If I have polar coordinates of a line, how can I draw it on an image in OpenCV and python? LineThe function takes 2 points, but only draws line segments. I want to draw a line from one edge of an image to the other. Robert Caspary: Just count 2 points.