简体   繁体   中英

how to convert Bitmap into a View?

I have a back.png file which I need to

  1. assign to a variable and convert to bitmap
  2. apply a hue function to it
  3. 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 it 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM