I have an image view pager which will select an image.But i want to crop this image with zoomIn and ZoomOut function in image.How I can do this?
mImageCaptureUri=Uri.parse("android.resource://app.islamic.unikacomp.myapplication/" +sliderImagesId[num]);
// Retrieve a WallpaperManager
WallpaperManager myWallpaperManager = WallpaperManager.getInstance(Animalwallpaper.this);
try {
// Change the current system wallpaper
myWallpaperManager.setResource(sliderImagesId[num]);
// Show a toast message on successful change
Toast.makeText(Animalwallpaper.this,"Wallpaper successfully changed", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
// TODO Auto-generated catch block
}
You can find multiple library on Github
Here are the few-
Android Image Cropper
Croper
Related
I have URL to PNG image file.
I want to get this image file and set it as a source for an ImageView.
My code:
URL iconURL = null;
try {
iconURL = new URL("https://maps.gstatic.com/mapfiles/place_api/icons/worship_general-71.png");
} catch (MalformedURLException e) {
e.printStackTrace();
}
Bitmap icon = null;
try {
icon = BitmapFactory.decodeStream(iconURL.openConnection().getInputStream());
} catch (IOException e) {
e.printStackTrace();
}
myImageView.setImageBitmap(icon);
If I place a breakpoint into the line with decodeStream() the app stops and I see the following:
If I run the app in regular mode, it just stops!
Can someone explain what is wrong here and how to do it correctly?
Thanks.
If you just want to show the image on your ImageView then you can use Picasso Library.
Put below dependency in build.gradle file
'com.squareup.picasso:picasso:2.71828'
And use below java code for loading your image from URL to your ImageView
Picasso.get()
.load(url)
.into(imageView);
i'm using these codes to set my image from server as wallpaper :
WallpaperManager wpm = WallpaperManager.getInstance(MainActivity.this);
InputStream ins;
try {
String xlx = "http://myserver.com/myimage.jpg";
ins = new URL(xlx).openStream();
wpm.setStream(ins);
} catch (IOException e) {
e.printStackTrace();
}
it's working and my image will set as wallpaper,
but my problem is that it is not setting full image as wallpaper, so how should i do to set full image as wallpaper without cropping?
set imageview property in your layout xml file.
android:scaleType="fitXY"
I am trying to change Android wallpaper using code. I am using the WallpaperManager class, but with no prevail. I used a .png image in the /drawable directory. I am getting an error that says, "Expected resource of type raw". When I run the application(when that method runs), it crashes. I must be victim of a really stupid mistake. The method changeWallpaper() is run after the user taps a button. Here is my code:
public void changeWallpaper(View view) {
try{
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
wallpaperManager.setResource(R.drawable.material_wallpaper);
String successMessage = "Wallpaper Changes";
Toast.makeText(this, successMessage, Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
String failedMessage = "Operation failed";
Toast.makeText(this, failedMessage, Toast.LENGTH_SHORT).show();
}
}
EDIT: There is no "raw" folder in my /res/ directory.
If you want to stay with Drawable, you can convert the resource into a Bitmap and then set it as wallpaper by using setBitmap(Bitmap _bitmap) (see WallpaperManager).
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getActivity().getApplicationContext());
Bitmap bitmap = BitmapFactory.decodeResource(getActivity().getResources(), R.drawable.material_wallpaper);
wallpaperManager.setBitmap(bitmap);
When setting the wallpaper I'm using an int and then I'm converting it into a bitmap with decodestream but the wallpaper is still not set.
Here is my code
InputStream y = getResources().openRawResource(friendship);
Bitmap b = BitmapFactory.decodeStream(y);
try {
getApplicationContext().setWallpaper(b);
Toast.makeText(this, "Wallpaper Set!", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
Is the permission SET_WALLPAPER set in the manifest file? Android docs link
Further more, the method that you are using is deprecated. You should be using WallpaperManager apis
I have used the following code, able to get the image but when I am trying to put it on Layout background(Linear Layout), the image quality gets reduced and it shows a blurred image.
URL img_value = null;
try {
img_value = new URL("http://graph.facebook.com/"+userId+"/picture?type=large");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Bitmap mIcon1 = null;
try {
BitmapFactory.Options opt=new BitmapFactory.Options();
opt.inSampleSize=1;
// mIcon1 = BitmapFactory.decodeFile(pathoffile,opt);
mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream(),null,opt);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ll=(LinearLayout) findViewById(R.id.ll);
BitmapDrawable background = new BitmapDrawable(mIcon1);
ll.setBackgroundDrawable(background);
It looks like you're trying to set that image to the background of a LinearLayout. I am going to assume that this background is roughly the size of the phone's screen.
I just tried out that facebook URL and the size of the image I am getting back is 180x195.
Considering the smallest Android screen I am aware of is 240x320, that image will have to be blown up on every single Android phone. This will cause the image to look blurry, as the resolution of the image is much lower than that of Android screens.
I recommend you find higher resolution images for your backgrounds.