Hi,
I found an answer to my previous question (the code for it is attached
below).
i think the solution is not too elegant so if you have any input on how i
can make it less hard coded i would love to hear it
for example i would like to set the name of the original image with xml and
also the coordinated that i would like to crop from it. and then be able to
extract this information from the parser. what would be the best method of
doing that?

if anyone is interested here is the code i used to get there:
Bitmap orgBmp = BitmapFactory.decodeResource(res,
R.drawable.sym_keyboard_delete);
        Bitmap  cropedBitmap = Bitmap.createBitmap(orgBmp, 0, 0, 20, 10);
        BitmapDrawable bitMapDraw = new BitmapDrawable(cropedBitmap);
        key.icon= bitMapDraw;



On Wed, Jul 29, 2009 at 11:50 PM, Spektor Yaron <[email protected]> wrote:

> Hi,
> I am trying to crop an image on a key for a soft keyboard.
> i want to do the following:
> 1.create a key with an icon (from a Bitmap)
> 2.take that Bitmap and crop it
> 3.set the new Bitmap back on the key as an icon
> Optional:
> 4.do some or most of this from the XML using the parser (i could not get a
> hook to the res/drawable/<image name> looking at the Xml Parser)
>
> here is what i do:
>
>    protected Key createKeyFromXml(Resources res, Row parent, int x, int y,
>             XmlResourceParser parser) {
>          Key key = new MyKey(res, parent, x, y, parser);//create a normal
> key
>         Bitmap orgBmp = BitmapFactory.decodeResource(res,
> R.drawable.sym_keyboard_delete);//i took a new hard-coded image here, but
> prefer this to be coming from the xml instead, in the MyKey constructor)
>         Bitmap  cropedBitmap = Bitmap.createBitmap(orgBmp, 0, 0, 20, 10);
> //crop the image
>         Canvas canvas = new Canvas(cropedBitmap);//put it in a canvas,
> since draw() only accepts canvas
>         if(key.icon!=null){ //if icon exists, draw it back on the key
>             key.icon.draw(canvas);
>         }
>         return key;
>     }
>
> Any ideas why this does not work?
> any simpler solutions for this?
> Thanks,
>
> --
>
>


-- 
Yaron Spektor

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to