android - Java Bitmap change hue -
here code:
public static bitmap processing(bitmap src, float hue) { int width = src.getwidth(); int height = src.getheight(); bitmap bitmap = bitmap.createbitmap(width, height, src.getconfig()); for(int x = 0; x < width; x++) { (int y = 0; y < height; y++) { int newpixel = huechange(src.getpixel(x, y), hue); bitmap.setpixel(x, y, newpixel); } } return bitmap; } private static int huechange(int startpixel, float hue) { float[] hsv = new float[3]; //array store hsv values color.colortohsv(startpixel,hsv); //get original hsv values of pixel hsv[0]=hsv[0]+hue; //add shift hue of hsv array hsv[0]=hsv[0]%360; //confines hue values:[0,360] return color.hsvtocolor(color.alpha(startpixel),hsv); }
problem is: processing
takes 3300ms if src bitmap size 480x480. , it's long me.
what fastest way it?
done!
fastest way use opencv ndk.
this worst possible way this. if ever think of using setpixel- don't. you're wrong.
the right way:
canvas canvas = new canvas(bitmap); canvas.drawcolor(color);
Comments
Post a Comment