[英]How to achieve a motion blur effect like this?
Smartisan OS的氣象應用程序具有以下效果:將格式從攝氏溫度更改為華氏度時,溫度數字將像這樣滾動: 運動模糊效果示例
我認為數字滾動時並不是簡單的模糊效果,因為您可以從圖像中看到這些數字僅在垂直方向上模糊。 數字首先以低速滾動,然后更快。 並且模糊半徑也隨着滾動而變長。 對我來說,這種效果並不容易實現。
只需創建一個始終在畫布上繪制的自定義視圖即可。 您必須自己處理上下運動,在這種情況下,您將無法使用簡單的內置ui元素。 一旦您想要獲得滾動效果,只需繪制移動的文本多次,但是每次都會稍微偏移它並根據其速度更改它的不透明度。
在這種情況下,使用OpenGL可能會過大,因為這種情況僅與文本有關。 運動模糊將太困難,並且難以實現,並且將文本繪制到畫布上數十次只會對性能產生很小的影響。
希望我能幫上忙。
@andras的相同解決方案
/**
* use for 2D-Radial-Blur
*
* @param src
* @param dx It effetcs the speed. you can use 1/-1 for a test
* @param dy It effetcs the speed. you can use 1/-1 for a test
* @param times effects motion length
* @return
*/
public static Bitmap doRadialBlur(Bitmap src, int dx, int dy, int times) {
Bitmap dst = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(dst);
Matrix matrix = new Matrix();
Paint paint = new Paint();
canvas.drawBitmap(src, matrix, paint);
paint.setAlpha(51); // 51 / 255 =20%
for (int i = 0; i < times; i++) {
matrix.setTranslate(i * dx, i * dy);
canvas.drawBitmap(src, matrix, paint);
}
return dst;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.