I need to apply tint effect on image in Android. But the tint effect will only have ORANGE COLOR tint. If anyone has done this type of effect, please help me.

I have seen all the web links found by searching tint effect, but all the links and resources are applying all color tint.

I need to implement this effect on seekbar progress.

Thanks in advance.

有帮助吗?

解决方案

I have done that and here is the code. Its done on the seekbar progress and generates Yellow Tint effect on the image.

skTint.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar arg0) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar arg0) {
        }

        @Override
        public void onProgressChanged(SeekBar arg0, int progress,
                boolean arg2) {
            skTint.setProgress(progress);
            String hex = Integer
                    .toHexString((progress - 255 < 0 ? (progress - 255)
                            * -1 : (progress - 255)));
            hex = (hex.length() == 1 ? "0" + hex : hex);
            hex = (hex.length() > 2 ? hex.substring(0, 1) : hex);

            String g_factor = Integer
                    .toHexString((int) (255 - (progress / 3)));
            g_factor = (g_factor.length() == 1 ? "0" + g_factor : g_factor);

            String colorcode = "#FFFF" + g_factor + hex;

            Bitmap alteredBitmap = Bitmap.createBitmap(
                    resized_bitmap.getWidth(), resized_bitmap.getHeight(),
                    resized_bitmap.getConfig());
            Canvas canvas = new Canvas(alteredBitmap);
            Paint paint = new Paint();
            ColorFilter cf = new PorterDuffColorFilter(Color
                    .parseColor(colorcode), Mode.MULTIPLY);
            paint.setColorFilter(cf);
            Matrix matrix = new Matrix();
            canvas.drawBitmap(resized_bitmap, matrix, paint);
            imgeffect.setImageBitmap(alteredBitmap);
        }
    });

其他提示

SeekBar uses the app's R.attr.colorAccent theme attribute by default as the widget's tint color. In order to change the accent color for the widget, you can use a theme overlay as follows:

<style name="SeekBarLightTheme" parent="ThemeOverlay.AppCompat.Light">
    <item name="colorAccent">@color/seek_bar_color</item>
</style>

and then in your layout XML:

<SeekBar
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ...
    android:theme="@style/SeekBarLightTheme"/>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top