【问题标题】:Fatal signal 11 when drawing a circle on a canvas with a bitmap shader使用位图着色器在画布上绘制圆圈时出现致命信号 11
【发布时间】:2014-09-06 15:43:23
【问题描述】:

我正在尝试用我存储在手机上的图像圈来绘制一个网格视图。如同

但我不想使用纯色/渐变色,而是使用图像。相关代码是

被绘制的视图

<ImageView
    android:id="@+id/img_color_selected"
    android:layout_width="35dp"
    android:layout_height="35dp"
    android:src="@drawable/ic_colorpicker_swatch_selected"
    android:layout_centerInParent="true"
    android:visibility="gone" />

在画布上绘图

   @Override
    public void draw(Canvas canvas) {
        Bitmap bitmap = BitmapFactory.decodeResource(RaiseTheBarApplication.getInstance().getResources(), patternResource);
        BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        Paint paint = new Paint();
        paint.setColorFilter(new LightingColorFilter(progressColor, 1));
        paint.setShader(shader);
        canvas.drawCircle(canvas.getWidth() / 2, canvas.getHeight() / 2, RaiseTheBarApplication.getInstance().getResources().getDimensionPixelSize(R.dimen.choose_color_radius), paint);
    }

choose_color_radius 为 20dp

网格视图

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rtb_dialog"
android:orientation="vertical">

<GridView
    android:id="@+id/gv_color_choice"
    android:layout_width="wrap_content"
    android:layout_height="250dp"
    android:columnWidth="65dp"
    android:numColumns="auto_fit"/>

<com.lvl.xpbar.views.baseviews.AFGTextView
    android:id="@+id/submit"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="20dp"
    android:text="@string/button_submit"
    android:textSize="18dp"
    android:gravity="center_horizontal"
    android:background="@drawable/dialog_submit_background_selector"
    android:paddingBottom="20dp"
    android:layout_marginTop="5dp" />

如果我使用 Canvas#drawBitmap 它工作正常,但我使用上面的逻辑我得到

09-06 11:34:06.702 31659-31659/? A/libc:致命信号 11 (SIGSEGV) at 0x797ba000 (code=2), thread 31659 (com.lvl.xpbar)

感谢任何帮助

【问题讨论】:

  • 尝试使用软件加速而不是硬件加速(如果有的话)
  • onDraw 方法中没有任何警告吗?

标签: android


【解决方案1】:

感谢@greywolf82,我通过使用禁用此视图的硬件加速解决了这个问题

setLayerType(LAYER_TYPE_SOFTWARE, null);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多