How can I get zoom functionality for images?
I used a WebView and loaded the image from the memory via
webview.loadUrl("file://...")
The WebView handles all the panning zooming and scrolling. If you use wrap_content the webview won't be bigger then the image and no white areas are shown.
The WebView is the better ImageView ;)
How do I pan and zoom an image?
I'm not sure what you mean by "doesn't work" but you're on the right track.
Check out https://github.com/flutter/flutter/blob/master/examples/layers/widgets/gestures.dart for a working example of a widget you can pan, pinch, and scale.
Zoom in and out of images in Java
You can easily achieve this by using scale transforms on the original image.
Assuming your the current image width newImageWidth
, and the current image height newImageHeight
, and the current zoom level zoomLevel
, you can do the following:
int newImageWidth = imageWidth * zoomLevel;
int newImageHeight = imageHeight * zoomLevel;
BufferedImage resizedImage = new BufferedImage(newImageWidth , newImageHeight, imageType);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, newImageWidth , newImageHeight , null);
g.dispose();
Now, replace the original image, originalImage
, in your display area by resizedImage
.
How to implement zoom effect for image view in android?
Lazy man can use this lib, Just import inside your project and
ImageView mImageView;
PhotoViewAttacher mAttacher;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Any implementation of ImageView can be used!
mImageView = (ImageView) findViewById(R.id.iv_photo);
// Set the Drawable displayed
Drawable bitmap = getResources().getDrawable(R.drawable.wallpaper);
mImageView.setImageDrawable(bitmap);
// Attach a PhotoViewAttacher, which takes care of all of the zooming functionality.
mAttacher = new PhotoViewAttacher(mImageView);
}
// If you later call mImageView.setImageDrawable/setImageBitmap/setImageResource/etc then you just need to call
mAttacher.update();
Related Topics
Programmatically Obtain the Phone Number of the Android Phone
Jdbc VS Web Service For Android
Android Check Internet Connection
How to Call Android Contacts List
Android Imageview Zoom-In and Zoom-Out
Set Style For Textview Programmatically
Static Way to Get 'Context' in Android
How to Change the Status Bar Color in Android
How to Filter a Recyclerview With a Searchview
Firebase Onmessagereceived Not Called When App in Background
J2Me/Android/Blackberry - Driving Directions, Route Between Two Locations