how to convert Bitmap into a View?
I have a back.png file which I need to
- assign to a variable and convert to bitmap
- apply a hue function to it
- and put it back
a = BitmapFactory.decodeResource(this.getResources(),R.drawable.back); b = Hue(a); View c = (View)findViewById(R.drawable.back); ///need to make View C = Bitmap B ... but how?
Here's my code so far, everything works, only I don't know how to assign my bitmap "b" back to view "c" ... any ideas?
Thanks!
backrepeat.xml
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/back"
android:tileMode="repeat" />
AbsoluteLayout al = (AbsoluteLayout)findViewById(R.id.setLay);
Drawable dback = al.getBackground();
a = ((BitmapDrawable)dback).getBitmap();
//b = Hue(a);
d =new BitmapDrawable(a);
al.setBackgroundDrawable(d);
Edit, tired that one, but converting from a drawable to a bitmap and then back again makes i开发者_如何学Pythont loos is tileing. I just get one bitmap stretched all over the screen...
What I would do is have an ImageView in the layout XML (in this example it has ID of image), then use
ImageView c = (ImageView)findViewById(R.id.image);
Then you can assign the bitmap to it with
image.setImageBitmap(b);
wat r u doing...R.drawable.back must be a png file it cannot be a view....
i mean view u must be using would be the main view like relative,absoulte,frame etc. or an imageview....u had to have one of such views
edited-->>
d=new BitmapDrawable(bm);
rl.setBackgroundDrawable(d);
where rl is my relative layout
rl=(RelativeLayout)findViewById(R.id.brl);
精彩评论