0

Currently i have slider images, where each image is placed on single slide page with the "share" button on top of it. if clicked on share button current Page image should be shared via email and mms, to do this first i need to convert the images to bitmap from drawable. arg_object.getString("image")) is the url of image. i'm able to get for converting individual images but not for overall. please help me.

heres my code for it

Bitmap bbicon = { BitmapFactory.decodeResource(this.cordova.getActivity().getResources
                    (),"R.drawable."+arg_object.getString("image"))};

but on decodeResource i'm getting error as The method decodeResource(Resources, int) in the type BitmapFactory is not applicable for the arguments (Resources, String)

4

3 回答 3

1

I am no sure i understood right but:

  • if in arg_object.getString("image") you have the resource name then there is not a direct way to load the bitmap, but you can still manage to get it dinamically.

    first resolve the resource identifier by the name like this:

    String name = arg_object.getString("image");
    String defType = "drawable"
    String defPackage = "com.android.yourpackage";
    int drawableId = getActivity().getResources().getIdentifier( name , defType, defPackage );
    

    now that you have the resource id you can easly create a bitmap with one of the BitmapFactory methods:

    Bitmap bitmap = BitmapFactory.decodeResource( getActivity().getResources(), drawableId );
    
  • if instead in arg_object.getString("image") you have the image uri, just use:

    Bitmap bitmap = BitmapFactory.decodeFile( arg_object.getString("image") );
    
于 2013-11-07T08:47:42.230 回答
0

如果 imageView 是带有您的图像资源的 ImageView ,那么,

BitmapDrawble bd = (BitmapDrawable)imageView.getDrawable();

位图位图 = bd.getBitmap();

于 2013-11-07T08:56:09.160 回答
0

它应该是

int resourceID = getActivity().getResources().getIdentifier(arg_object.getString("image"), "drawable",getActivity().getPackageName());
Bitmap bbicon =  BitmapFactory.decodeResource(getActivity().getResources(),resourceID);

第二个参数是 id,它是一个 int 值。但是你有"R.drawable."+arg_object.getString("image")它使它成为一个字符串。我猜你得到了名字,arg_object.getString("image")你可以得到上面的资源ID。

欲了解更多信息

http://developer.android.com/reference/android/graphics/BitmapFactory.html

public static Bitmap decodeResource (Resources res, int id)

Added in API level 1
Synonym for decodeResource(Resources, int, android.graphics.BitmapFactory.Options) will null Options.

Parameters
res The resources object containing the image data
id  The resource id of the image data
Returns
The decoded bitmap, or null if the image could not be decoded.
于 2013-11-07T08:51:38.683 回答