How to read the jpg files in view? - android

I had a image in drawable folder. I want to load using BitmapFactory.decodeFile. What is the file path in this case??

check out this way, provide resources id as a "path"
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.image_resource);

Related

Error when creating Bitmap from an image

I am trying to draw an image from a file, a png file.
I need to draw it as a bitmap on a canvas but i cant get the file into the bitmap object without getting an error, after trying for a lot of time i need some help.
example of what i tried:
Resources res = getResources();
Bitmap bitmap = BitmapFactory.decodeResource(res, R.drawable.myimage);
thanks!

How to open a JPG file as a BITMAP stored on the .../res/drawable-hdpi/?

I want to open a JPG file as Bitmap that stored on drawable-hdpi folder.
But i do not use R.drawable.filename , because I don`t know its name. I only have a String of its name.
String IMAGE = String.valueof(Random());
In otherwise, I want to open an Image file with name IMAGE stored on the .../res/drawable-hdpi/.
Thanks for any help.
You can get a Bitmap by
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.myimage);

Set wallpaper from external storage

So I've got my image gallery project all set up with images saved online and not within the application. It works great. But what I want to do is get the facility to set the image as a wallpaper.
I've got the image to download and save in the external storage as packagename.jpg
Everywhere I've searched for examples on how to set the wallpaper all seem to be based on the image being within the application.
Anyone have any pointers on how to use wallpapermanger to set an image from external storage as the wallpaper?
You need to first retrieve the file from the SDCard and decode the image into a Bitmap using BitmapFactory then you can set the bitmap using WallpaperManager's setBitmap() method.
File file = new File(Environment.getExternalStorageDirectory(), "/directory/yourimage.jpg");
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getBaseContext());
Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
wallpaperManager.setBitmap(myBitmap);

Creating Image instance from drawable images in android

i am creating digital signature app using iTextG jar, to add water mark on the signature field, iText's
appearance.setImage(Image.getInstance(signedImagePath));
Requires a path of the watermark image, i want to use image from drawable folder of android, kindly suggest me i am not getting how to create Image instance from drawable, suggest if any other option is there?
You use ImageInstance something like this.
Bitmap bitmap = BitmapFactory.decodeResource(getBaseContext().getResources(),R.drawable.yourimage);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100 , stream);
Image myImg = Image.getInstance(stream.toByteArray());
Hope this helped.
http://developer.android.com/reference/android/graphics/BitmapFactory.html#decodeResource(android.content.res.Resources, int, android.graphics.BitmapFactory.Options)

Is it possible to retrieve an image from the data folder in an android app?

I want to retrieve an image from my data/data/com.apps.myapp/images folder and display it in an ImageView. Any clue?
Try this :
Bitmap bitmap = BitmapFactory.decodeFile("data/data/com.apps.myapp/images/img.png");
ImageView imgView = (ImageView) this.findViewById(R.id.imgViewId);
imgView.setImageBitmap(bitmap);
There are several components involved in this.
To get the path of your data folder you can use the method getDir in the Context.
Now you have to know the file name and open an stream here again the Context class is your friend. Now the stream can be decoded into a Bitmap via a Bitmap Factory.
After you got a Bitmap create a BitmapDrawable from it and pass it to your ImageView

Categories

Resources