Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

图片放到之后有黑色边框 #281

Open
szdenny2 opened this issue Mar 1, 2024 · 2 comments
Open

图片放到之后有黑色边框 #281

szdenny2 opened this issue Mar 1, 2024 · 2 comments
Labels

Comments

@szdenny2
Copy link

szdenny2 commented Mar 1, 2024

image

@szdenny2 szdenny2 changed the title 图片放到之后又黑色边框 图片放到之后有黑色边框 Mar 1, 2024
@szdenny2
Copy link
Author

szdenny2 commented Mar 1, 2024

image
这个是原始的文件
下面是获取bitmap的方法
private Bitmap generateImage()
{
// Create a Bitmap to render our SVG to
Bitmap bm = Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888);
// Create a Canvas to use for rendering
Canvas canvas = new Canvas(bm);

  // Clear the background to white
  canvas.drawRGB(255, 255, 255);

  Random  random = new Random();

  for (int i=0; i<NUM_BOUQUETS; i++)
  {
     // Save the canvas state (because we are going to alter the transformation matrix)
     canvas.save();

     // Choose a random scale
     // If we don't specify a viewport box, then AndroidSVG will use the bounds of the Canvas
     // as the viewport.  So a scale of 1.0 corresponds to that size.
     // A scale of 0.1 would draw the SVG at 1/10th of the size of the Canvas/Bitmap.
     float scale = SCALE_MIN + random.nextFloat() * (SCALE_MAX - SCALE_MIN);

     // Choose a random position
     float  x = random.nextFloat();   // 0.0 -> 1.0
     float  y = random.nextFloat();

     // If we just draw the SVG at x,y, then it will be drawn below and to the right of that.
     // But we want to centre at x,y instead. We can do that by subtracting half the scale.
     x -= scale / 2;
     y -= scale / 2;

// canvas.translate(x * WIDTH, y * HEIGHT);
canvas.scale(50, 50);

     // Now render the SVG to the Canvas
     bouquet.renderToCanvas(canvas);

     // And restore the Canvas's matrix to what it was before we altered it
     canvas.restore();
  }

  return bm;

}

@BigBadaboom
Copy link
Owner

I am assuming your SVG does not have a dark stroke (border)?

Then I think you are seeing this because you are drawing the SVG shape 10 times (NUM_BOUQUETS ) in exactly the same place. The partially transparent anti-aliased pixels, at the edge of the SVG shape, are adding together making a dark halo around the shape.

If you remove the loop, so that you draw the image only once, then I think you will see that the dark line will disappear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants