Bitmapshader scalierbar ?

  • Antworten:0
mcfly
  • Forum-Beiträge: 286

04.03.2013, 16:30:47 via Website

Hallo zusammen

Ich habe ein Problem beim zeichnen eines Pfades mit einer Füllung.

Ich zeichne eine Path mit canvas.drawpath(), den ich mit einer Schraffur (
Bitmap mit einem Bitmapshader ) befülle. Sobald ich den Pfad mit canvas.scale(5f,5f) vergrössere wird die
Schraffur (Bitmap im Bitmapshader) auch vergrössert und das sieht unschön aus.

Hat jemand einen Tip, wie ich die gleiche saubere ( nicht verpixelte ) Schraffur auch mit einer Vergrösserung durch scale erreichen kann ?



Nach dem zoomen mit canvas.scale()




1canvas.scale(scalex, scaley);
2 canvas.translate(itranslatex, itranslatey);
3
4
5 fillBMP = makePatternCross(fscalex, 1, Color.GREEN/*,fscalex,fscaley*/);
6 fillBMPshader = new BitmapShader(fillBMP, BitmapShader.TileMode.REPEAT, BitmapShader.TileMode.REPEAT);
7 paintshader = new Paint();
8 paintshader.setShader(fillBMPshader);
9
10
11 canvas.drawPath(cpath.path, paintshader);

1private static Bitmap makePatternCross(float fSize, float fStrokewith,int iColor) {
2 Log.v("Create Patter makePatternCross","makePatternCross");
3
4 float fBitmapSizeOrig = 10;
5 fBitmapSizeOrig=fBitmapSizeOrig*fSize;
6 Bitmap bm = Bitmap.createBitmap((int)fBitmapSizeOrig,(int) fBitmapSizeOrig,Bitmap.Config.ARGB_8888);
7 Canvas c = new Canvas(bm);
8 //c.scale(200, 200);
9 c.drawColor(Color.WHITE);
10 Paint p = new Paint();
11 p.setColor(iColor);
12 //p.setStrokeWidth(iStrokewith);
13 p.setStrokeWidth(fStrokewith/fSize);
14 p.setStrokeWidth((float) 0.000001);
15 c.drawLine(0, 0, fBitmapSizeOrig, fBitmapSizeOrig, p);
16 c.drawLine(0, fBitmapSizeOrig, fBitmapSizeOrig, 0, p);
17
18 if (fSize != 1) {
19 int iNewSize = (int) (( fBitmapSizeOrig) * fSize);
20 bm = Bitmap.createScaledBitmap(bm, iNewSize, iNewSize, false);
21 }
22
23 int width = bm.getWidth();
24 int height = bm.getHeight();
25 for (int x = 0; x < width; x++) {
26 for (int y = 0; y < height; y++) {
27 if (bm.getPixel(x, y) == Color.WHITE) {
28 bm.setPixel(x, y, Color.TRANSPARENT);
29 } else {
30 // bm.setPixel(x, y, bm.getPixel(x, y));
31 }
32 }
33 }
34 return bm;
35}

Antworten