让一张图片从模糊慢慢变清晰动画过程

系统 1690 0
让一张图片从模糊慢慢变清晰动画过程


让一张图片从模糊慢慢变清晰动画过程

    
import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;

import com.enrique.stackblur.StackBlurManager;

public class MainActivity extends Activity {
    
	private ImageView    iv;
	private SeekBar      seekBar;
	private StackBlurManager stackBlurManager;
	private String IMAGE_TO_ANALYZE = "android_platform_256.png";
	private int blurMode=0;
	private int radius=30;
	private int step=2;
	Handler handler = new Handler();
	Runnable runnable = new Runnable() {
		@Override
		public void run() {
			// TODO Auto-generated method stub
			radius -= step;
			if (radius < 0) {
				handler.removeCallbacks(runnable);
				return;
			}
			onBlur(radius);
			handler.postDelayed(this, 30);
		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		iv=(ImageView)findViewById(R.id.imageView);
		seekBar=(SeekBar)findViewById(R.id.blur_amount);
		
		stackBlurManager = new StackBlurManager(getBitmapFromAsset(this, "av.png"));
		onBlur(radius);
		
		handler.postDelayed(runnable, 1000);
		
		seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
			
			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
				
			}
			
			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
				
			}
			
			@Override
			public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
				int radius = progress;
				onBlur(radius);
			}
		});
		
	}
	
	private Bitmap getBitmapFromAsset(Context context, String strName) {
        AssetManager assetManager = context.getAssets();
        InputStream is=null;
        Bitmap bitmap = null;
        try {
            is = assetManager.open(strName);
            bitmap = BitmapFactory.decodeStream(is);
        } catch (IOException e) {
            return null;
        }
        return bitmap;
    }

	public void setBlurMode(int mode) {
		this.blurMode = mode;
		onBlur(radius);
	}

	private void onBlur(int radius) {
		switch(blurMode) {
			case 0:
				iv.setImageBitmap( stackBlurManager.process(radius) );
				break;
			case 1:
				iv.setImageBitmap( stackBlurManager.processNatively(radius) );
				break;
			case 2:
				iv.setImageBitmap( stackBlurManager.processRenderScript(this, radius) );
				break;
		}
	}
}

  


    
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFF"
    android:gravity="center_horizontal"
    android:orientation="vertical" >

    <SeekBar
        android:id="@+id/blur_amount"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="50" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />

</LinearLayout>

  

让一张图片从模糊慢慢变清晰动画过程


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论