Android图片叠加效果

时间:2016-05-12 21:34:20

标签: java android image overlay

我想用两张图片创建叠加效果。一个图像从图库和第二个图像加载,首次加载时必须应用噪声效果。 我的代码在片段中的onViewCreated:

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    imageView = (ImageView) view.findViewById(R.id.imageView);

    String picturePath = getActivity().getIntent().getStringExtra("image");

    int targetWidth = 600;
    int targetHeight = 400;
    BitmapFactory.Options options = new BitmapFactory.Options();

    //first decode image dimensions only - not the image bitmap itself
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(picturePath, options);

    //image width and height before sampling
    int currHeight = options.outHeight;
    int currWidth = options.outWidth;

    //variable to store new sample size
    int sampleSize = 1;

    //calculate the sample size if the existing size is larger than target size
    if (currHeight>targetHeight || currWidth>targetWidth)
    {
        //use either width or height
        if (currWidth>currHeight)
            sampleSize = Math.round((float)currHeight/(float)targetHeight);
        else
            sampleSize = Math.round((float)currWidth/(float)targetWidth);
    }

    //use the new sample size
    options.inSampleSize = sampleSize;
    options.inJustDecodeBounds = false;

    //get the file as a bitmap
    Bitmap img = BitmapFactory.decodeFile(picturePath, options);


    imageView.setImageBitmap(img);
}

例如,我有这个图像(我无法加载2个以上的图像) 有噪音的图像:Image with effect 我想创建这样的东西Created image 是否有可能,如果可能的话可以帮助我?

0 个答案:

没有答案