android - Canvas doesn't draw bitmap when a ColorMatrixColorFilter is used -
i having difficulties using colormatrixcolorfilter modify color pixels in bitmap. if use bitmap local file system (a jpg), works. however, if use bitmap created buffer, nothing drawn on canvas.
in particular, i'm using following code create colormatrix:
float matrix[] = new float[] { 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0 }; rbswap = new colormatrix(matrix); paint = new paint(paint.filter_bitmap_flag); paint.setcolorfilter(new colormatrixcolorfilter(rbswap)); the above used create colormatrixcolorfilter used swap red , blue colors.
if create bitmap using following code, works:
bitmap = bitmapfactory.decoderesource(context.getresources(), r.drawable.picture); if create bitmap using following code, nothing ever drawn canvas:
bitmap = bitmap.createbitmap((int) width, (int) height, bitmap.config.argb_8888); srcbuffer = bytebuffer.wrap(data); srcbuffer.rewind(); bitmap.copypixelsfrombuffer(srcbuffer); my ondraw() looks following:
public void ondraw(canvas canvas) { canvas.drawbitmap(spicebmp, offsetx, offsety, paint); } if don't set colorfilter, bitmap renders on canvas. if set colorfilter, black screen - nothing appears render. if use jpg bitmap instead of 1 creating via buffer, draws red/blue swapped.
i changed matrix same identity matrix , bitmap rendered properly. if change single float in matrix (like 1s .5s or 0), nothing drawn.
i've checked make sure bitmap has enough "bytes" represent bitmap. bitmap.bytecount() == srcbuffer.limit() true - bytes in buffer same should present width/height passing in.
i put try/catch exception during ondraw poured through logcat output, didn't see there. poked around in android bitmap drawing code , saw following:
// nothing draw if (fclip->isempty() || bitmap.width() == 0 || bitmap.height() == 0 || bitmap.getconfig() == skbitmap::kno_config || (origpaint.getalpha() == 0 && origpaint.getxfermode() == null)) { return; } i don't have ability trace c++ code in core can't tell if triggering. know bitmap's width , height both non-zero (they 800 , 600) , know bitmap set on creation of type argv_8888 , exact same paint object used both jpg loaded disk (the 1 works) , 1 create using copypixelsfrombuffer().
so i'm not sure doing wrong. presume flag or property in bitmap incompatible colorfiltering, simple bytebuffer of proper size of type argb_8888. , of course, exact same code (paint object, etc) used set filter.
so there else need doing bitmap? colormatrix/filter?
as turns out, minsdkversion set version 10. when added targetsdkversion of 14, works fine. apparently, colormatrixcolorfilter has different behavior/interface older versions of android (pre-honeycomb).
in each of older versions, matrix values applied alpha channel resulted in 0 if alpha channel byte 0. fifth value in matrix not added formula.
Comments
Post a Comment