Showing posts with label Get Images Dynamically. Show all posts
Showing posts with label Get Images Dynamically. Show all posts

Load Images From Phone in Android by Specifying Image Path

Load Images From Phone in Android

Sample Code


private Bitmap getBitmap(String imageFilePath)
{



// Load up the image's dimensions not the image itself

BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();

bmpFactoryOptions.inJustDecodeBounds = true;

Bitmap bmp = BitmapFactory.decodeFile(imageFilePath, bmpFactoryOptions);

int heightRatio = (int) Math.ceil(bmpFactoryOptions.outHeight/ (float) DISPLAYHEIGHT);

int widthRatio = (int) Math.ceil(bmpFactoryOptions.outWidth/ (float) DISPLAYWIDTH);

Log.v("HEIGHTRATIO", "" + heightRatio);

Log.v("WIDTHRATIO", "" + widthRatio);

// If both of the ratios are greater than 1, one of the sides of
// the image is greater than the screen


if (heightRatio > 1 && widthRatio > 1) {

if (heightRatio > widthRatio) {

// Height ratio is larger, scale according to it

bmpFactoryOptions.inSampleSize = heightRatio;

} else {

// Width ratio is larger, scale according to it

bmpFactoryOptions.inSampleSize = widthRatio;

}

}

// Decode it for real
bmpFactoryOptions.inJustDecodeBounds = false;

bmp = BitmapFactory.decodeFile(imageFilePath, bmpFactoryOptions);

return bmp;
}

Get Images Dynamically from Drawable Folder in android


//Sample code

Resources resClick = getResources();

Class res = R.drawable.class;

Field field = res.getField("image1");

int imgID = field.getInt(null);

//-----------------------------------------

Another method


----getResources().getResourceEntryName("image1")
 

Popular Posts

About Me

Only For Sharing Android Related Things...

Facebook Fan Page