How can I set dynamically created bitmap as livefolder icon in android? - android

How can I set dynamically created bitmap as livefolder icon in android?
LiveFolder takes EXTRA_LIVE_FOLDER_ICON as ShortcutIconResource. Is there a way to reference dynamically created bitmap as shortcuticonresource? In the following code segment instead of using icon as int value I would like to set the file path for the newly created bitmap file.
intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON,
Intent.ShortcutIconResource.fromContext(context, icon));

It is not possible to use bitmap from a file in a live folder.

Related

Android avoid image scalling in Imageview for Image Mapping like Html

Hi Am trying to implement image mapping as like html in android. For that i referred this project. Its work good when i access the image from drawable-nodpi folder. But when i access from other drawable folder the image get scaled as per the android concepts. Here i used drawable folder for checking purpose only. Actually i get image from back end service.
I also tried with bitmap by setting the no density.
Bitmap bm;
bm=BitmapFactory.decodeResource(getResources(), R.drawable.blueprint);
bm.setDensity(Bitmap.DENSITY_NONE);
mImageMap.setImageBitmap(bm); //mImageMap is customized view which extends Imageview
But it's not working. Am also tried as per this post. Its not working.Is there any way to load image to image view without scaling?
you can use Bitmap.createScaledBitmap with the orignal mesaures of the picture..
int width = orignal bitmap width
int height = orignal bitmap height
Bitmap bm;
bm = getBitmap... from network
bm = Bitmap.createScaledBitmap(bm,width,height,true);
this will create a image scaled properly and just place it in the ImageView.

Imageview Src path in Android in Appium

In our Android app, we use placehold images in our thumbnails until the server returns a valid image. The Android devs change the src of the ImageView when an image is found. I am unable to find the src of the ImageView because when i do a get_attribute('src'), nothing comes up. Is there a way to get the src of an ImageView?
first you need to set tag and then you can surely get the resource of ImageView.
myImageView.setTag(R.drawable.currentImage); //set this along when you set your image source
int drawableId = (Integer)myImageView.getTag(); //get the resource
I solved this by setting the ImageView description like .setContentDescription({image_resource})
and then getting it on appium with
.getAttribute("name")

Converting bitmap to drawable in Android

I'm downloading the image from server and storing it in bitmap object. I want to set this image as background for button. But the button doesn't have the property setImageBitmap. So is there anyway I can set the background of button with the downloaded bitmap image? Like by converting the bitmap to drawable? Sorry, I'm new to Android, please bear with my mistakes (if any).
P.S : I want to use button control only. Because I want some text at the bottom of each buttons and I'm creating these buttons dynamically.
The best way to convert a Bitmap to drawable in android is as follows,
Drawable drawable = new BitmapDrawable(getResources(), bitmap);
where bitmap is the name the Bitmap. Then set the drawable as your Button background as follows,
btn.setBackground(drawable);
N.B: Without specifying getResources() as the first argument, you may experience inconsistent image sizing across different screen densities.
for more info refer this
http://developer.android.com/reference/android/graphics/drawable/BitmapDrawable.html
Simply use BitmapDrawable.
Drawable drawable=new BitmapDrawable(contact_pic);
Convert Bitmap to BitmapDrawable like this
Drawable drawable = new BitmapDrawable(getResources(),your_bitmap);
and then set it as background to button as ,
button.setBackgroundDrawable(drawable);
P.S. You can also do the same inline as ,
button.setBackgroundDrawable(new BitmapDrawable(getResources(),your_bitmap));
This is how to do it, I've used several times:
Drawable drawable = (Drawable)new BitmapDrawable(Bitmap);
Button button= new Button(this);
button.setBackground(drawable);

display image with transparent color at runtime

I try to display a jpg in android-canvas with a specific transparent color.
It works well with a png and I also know how to convert a jpg to png with java so at the end I have a new png-file on the filesystem.
Now my question:
Is there a way to read a jpg file from the filesystem, set a transparent color at runtime (convert to png) and display the image at runtime ?
additional comment:
I try to do this in my custom view with the ondraw method and drawbitmap. I can't use an imageview. :-(
regards
Andreas
don't make the image transparent but the view.
ImageView myImage = (ImageView) findViewById(R.id.img);
myImage.setAlpha(value);
Value is something between 0 and 255. The lower the number, the more transparent the imageview.

Android: How to: set the Image of ImageSwitcher by a Bitmap? setImageBitmap doesn't exist?

i can't find setImageBitmap from ImageSwitcher. is there a way to set it by a bitmap?
UPDATES1
then i found this -> set Image from file URI
But my case is, i have to draw something in the bitmap before it set to ImageSwitcher. So, is there no way to set it via bitmap? if no way, i have to output the image file from modified bitmap then use setImageURI. But this is wasting of memory.
UPDATES2
Alternative: Is there a way to dynamically store the image file from sdcard to R.drawable or R.raw to generate resource/drawable id. Then use it to setImageResource or setImageDrawable?
you can convert bitmap into drawable and assign drawable to image switcher as
Drawable drawable =new BitmapDrawable(bitmap);
mSwitcher.setImageDrawable(drawable);
You can wrap your Bitmap in BitmapDrawable and use ImageSwitcher.setImageDrawable.

Categories

Resources