androidsvg icon indicating copy to clipboard operation
androidsvg copied to clipboard

图片放到之后有黑色边框

Open szdenny2 opened this issue 1 year ago • 2 comments

image

szdenny2 avatar Mar 01 '24 09:03 szdenny2

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;

}

szdenny2 avatar Mar 01 '24 09:03 szdenny2

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.

BigBadaboom avatar Mar 03 '24 10:03 BigBadaboom

No further communication, so closing this ticket.

If you think this is still a bug, please let me know. I also just realised that this could be the same bug as #289.

BigBadaboom avatar May 07 '25 12:05 BigBadaboom

Marking this a duplicate of #289.

BigBadaboom avatar May 07 '25 14:05 BigBadaboom