1
を上書きします。私はまた、ビットマップの明確なオリジナルコピーが必要なので、ImageViewのイメージとして設定することができます。のrenderScriptブラーは、私が<em>ImageViewの</em>が含まれてい<em>のLinearLayout</em>の背景として設定するにはぼやけたビットマップを作成するために<strong>のrenderScript</strong>を使用しようとしています、元のビットマップ
ここに私のコードです:
ImageView mainImage;
Bitmap mainBMP, blurredBMP
LinearLayout background;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_work_area);
getImage(); // obtain bitmap from file
mainImage.setImageBitmap(mainBMP); // set the original bitmap in imageview
// create a blurred bitmap drawable and set it as background for linearlayout
BitmapDrawable drawable = new BitmapDrawable(getResources(), blur(mainBMP));
mainBackground.setBackground(drawable);
registerForContextMenu(objectImage);
registerForContextMenu(textArea);
}
private void getImage(){
String filename = getIntent().getStringExtra("image");
try {
FileInputStream is = this.openFileInput(filename);
mainBMP = BitmapFactory.decodeStream(is);
is.close();
} catch (Exception e) {
e.printStackTrace();
}
}
@TargetApi(17)
public Bitmap blur(Bitmap image) {
if (null == image) return null;
Bitmap outputBitmap = Bitmap.createBitmap(image);
final RenderScript renderScript = RenderScript.create(this);
Allocation tmpIn = Allocation.createFromBitmap(renderScript, image);
Allocation tmpOut = Allocation.createFromBitmap(renderScript, outputBitmap);
//Intrinsic Gausian blur filter
ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
theIntrinsic.setRadius(BLUR_RADIUS);
theIntrinsic.setInput(tmpIn);
theIntrinsic.forEach(tmpOut);
tmpOut.copyTo(outputBitmap);
return outputBitmap;
}
それでは、どのように私は作るのですか同じビットマップのの2つのコピー、そのうちの1つがでぼやけたと他方クリアでオリジナルです?
それはありました!ありがとう – AES
嬉しいです! –