Autore Topic: Ombreggiatura canvas  (Letto 741 volte)

Offline supertommino

  • Utente junior
  • **
  • Post: 77
  • Respect: +12
    • Mostra profilo
  • Dispositivo Android:
    Nexus 5
  • Play Store ID:
    supertommino
Ombreggiatura canvas
« il: 05 Settembre 2012, 18:02:11 CEST »
0
Stavo creando un rettangolo con CANVAS  (ma potrebbe anche essere un cerchio, una linea...) e impostando l'ombreggiatura, ma non funziona se Scelgo come target api 14, 15 o 16, solo con il mio nexus s (con jelly beans stock)(crea ugualmente il rettangolo ma non mette l'ombreggiatura), mentre con l'emulatore, abbassando il target o con altri telefoni funziona..
sbaglio io ho è un bug ?
Ecco il codice:
Codice (Java): [Seleziona]
package X.X.X;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

public class MicView extends View{

        String TAG = "micview";
       
        //variabili
        int l, a = 0;
        //stop variabili
       
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                // TODO Auto-generated method stub
                super.onMeasure(widthMeasureSpec, heightMeasureSpec);
               
                this.l = MeasureSpec.getSize(widthMeasureSpec);
                this.a = MeasureSpec.getSize(heightMeasureSpec);
                Log.i(TAG, "Misuro: altezza:"+a+" larghezza:"+l);
        }

        @Override
        protected void onDraw(Canvas canvas) {
                // TODO Auto-generated method stub
                super.onDraw(canvas);
               
                Log.i(TAG, "OnDraw");
                Paint p = new Paint();
                p.setColor(Color.CYAN);
                p.setShadowLayer(10, 20, 20, Color.RED);
                canvas.drawRect(0, 0, l/2, a/2, p);
        }

        public MicView(Context context, AttributeSet attrs) {
                super(context, attrs);
                // TODO Auto-generated constructor stub
        }

}

Offline DarnellNajanReed

  • Utente normale
  • ***
  • Post: 359
  • Respect: +49
    • Google+
    • Mostra profilo
  • Dispositivo Android:
    LG Optimus One, Acer Iconia A500/501, Asus Transformer Prime, Galaxy ACE, Galaxy S Plus, Galaxy S Advance P, Galaxy Tab 2 7.0, Google Nexus 7
  • Play Store ID:
    Luigi Notaro
  • Sistema operativo:
    OS X 10.8.3
Re:Ombreggiatura canvas
« Risposta #1 il: 06 Settembre 2012, 09:11:59 CEST »
+2
No, è conseguenza dell'abilitazione dell'accellerazione hw nel disegno della UI.
Dai un'occhiata qui:
http://developer.android.com/guide/topics/graphics/hardware-accel.html

In particolare:
Citazione
Unsupported Drawing Operations
When hardware accelerated, the 2D rendering pipeline supports the most commonly used Canvas drawing operations as well as many less-used operations. All of the drawing operations that are used to render applications that ship with Android, default widgets and layouts, and common advanced visual effects such as reflections and tiled textures are supported. The following list describes known operations that are not supported with hardware acceleration:

Canvas
clipPath()
clipRegion()
drawPicture()
drawTextOnPath()
drawVertices()
Paint
setLinearText()
setMaskFilter()
setRasterizer()
Xfermodes
AvoidXfermode
PixelXorXfermode

In addition, some operations behave differently with hardware acceleration enabled:

Canvas
clipRect(): XOR, Difference and ReverseDifference clip modes are ignored. 3D transforms do not apply to the clip rectangle
drawBitmapMesh(): colors array is ignored
Paint
setDither(): ignored
setFilterBitmap(): filtering is always on
setShadowLayer(): works with text only
PorterDuffXfermode
PorterDuff.Mode.DARKEN will be equivalent to SRC_OVER when blending against the framebuffer.
PorterDuff.Mode.LIGHTEN will be equivalent to SRC_OVER when blending against the framebuffer.
PorterDuff.Mode.OVERLAY will be equivalent to SRC_OVER when blending against the framebuffer.
ComposeShader
ComposeShader can only contain shaders of different types (a BitmapShader and a LinearGradient for instance, but not two instances of BitmapShader )
ComposeShader cannot contain a ComposeShader

If your application is affected by any of these missing features or limitations, you can turn off hardware acceleration for just the affected portion of your application by calling setLayerType(View.LAYER_TYPE_SOFTWARE, null). This way, you can still take advantage of hardware acceleratin everywhere else. See Controlling Hardware Acceleration for more information on how to enable and disable hardware acceleration at different levels in your application.

Offline supertommino

  • Utente junior
  • **
  • Post: 77
  • Respect: +12
    • Mostra profilo
  • Dispositivo Android:
    Nexus 5
  • Play Store ID:
    supertommino
Re:Ombreggiatura canvas
« Risposta #2 il: 06 Settembre 2012, 16:21:58 CEST »
0
Grazie era proprio quello
 :-)