How can zoom image with multiple Touch in android? - android

I am going to create image gallery. How can i zoom image using multiple touch. i got pinch-0.8 library but how can i use it. if you have any other idea then help me.
Zoom effect with ImageView in android.

There is a library available at Image Zoom
Download two files
ImageViewTouch.java
ImageViewTouchBase.java
To use image view inside your layout file, write following code
<com.package_name.ImageViewTouch
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:src="#drawable/image" />
NoTe
Make sure, you have put those files inside any package, like com.customview or something like that. So that you can refer that in layout file.
Link
You can download sample from sephiroth/ImageViewZoom

Related

How to overlay a custom drawing over a SurfaceView being used as camera preview?

What I want:
I want to make a Camera Activity (i.e. an Activity which shows the Camera Preview) in which a square shape (it's actually a bit complicated shape but I am saying square for simplicity) is overlay-ed on the camera preview, so that the user knows where to position the camera such that a particular square shaped real object is positioned inside that square shape overlayed on the camera preview.
Just like there is a face shape in the camera preview in the following image, so that the user can put their face there.
My Solution:
I thought of having a FrameLayout and then having SurfaceView for the camera preview and a VectorDrawable for the shape to be overlayed, as FrameLayout would Z-order its children such that VectorDrawable will end up being overlayed on SurfaceView.
Problems with it:
I need my app to be compatible with API 11 and above. So I'd have to use VectorDrawableCompat. To use VectorDrawableCompat, we need to set an AAPT flag. - source
The problem is that everywhere on the web, the way to set this flag is for Android Studio. (like the method described here) A few lines are to be added to the project's build.gradle file.
I couldn't find out how to set this flag in Eclipse. I kept searching, and ended up installing the Eclipse Buildship plugin to use Gradle in Eclipse. I followed this guide. When I added the Gradle nature to my Android project, I did get a build.gradle file. I pasted the code to enable that AAPT flag in it but it did not help my problem at all.
SO NOW I AM LOOKING FOR AN ALTERNATE METHOD TO ACHIEVE MY TASK. PLEASE TELL ME HOW CAN I DO IT, WITHOUT USING VectorDrawableCompat?
I agree that VectorDrawable is better than png file.
But I think png is acceptable, because ImageView with dp size will automatically scale the image.
This is example:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<SurfaceView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:scaleType="fitXY"
android:src="#drawable/face_shape"/>
</FrameLayout>

I want to enter images in my android activity. Where should I put the images?

I'm using Android Studio 1.2.2 I made a form activity and I want to insert an image. Where should I put the image? What changes I have to do in my mainactivity.java
file?
You can use Android's ImageView tag. You need to write it inside .xml file of your activity. You can take reference of it from android's devloper's website.
In Andorid studio you can not directly drag & drop images.
It will be good for you to take reference of any example.Here is the ImageView xml code.
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/android" />
You can now make this ImageView reference in your MainActivity (Java) like below:
ImageView imageView;
imageView = (ImageView) findViewById(R.id.imageView1);
Take a look at the docs: http://developer.android.com/guide/topics/resources/drawable-resource.html
Commonly, you will want to use some of the qualifiers by screen density and provide each image at different resolutions, docs here, this way lets Android pick up the best image size and scale it to match the phone screen.
Personally i use -nodpi and perform scalation by code, this way lets only have one copy of each image, and, gives you max control to position and size your images.
Hope this helps.

How to display a long list view with images without run out of memory?

I'm developing an app that display a listview with different images that are edited when the user click on them.
This is the code of my row.xml file.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="80dp"
android:layout_height="80dp"/>
<TextView
android:id="#+id/textView1"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_marginLeft="8dp"
android:text="TextView"
android:textSize="25sp"
/>
I'm using only one set of images, stored in the folder res/drawable/drawable-nodpi (Because I need them to keep its original size in order to edit them as bitmaps).
The problem is that those images are to big too be displayed in a single activity and therefore, when I create the listview it use a lot of memory and the list is scrolls with some lag. How can I display those images in the list without this problem? Should I create another set of smaller images to use them in the list? I've read post when the app save the images to the SD card, or the cache memory, but actually i'm not sure about the solution that fit best with my specific application.
Thanks in advance
You can use the following link below to make your list. Here they free the image cache once it is not seen. Using this you can put many image sin your list :
https://github.com/thest1/LazyList
Hope this helps you.
Try this..
Android-Universal-Image-Loader libriary. This project aims to provide a reusable instrument for asynchronous image loading, caching and displaying. It is originally based on Fedor Vlasov's project and has been vastly refactored and improved since then.
https://github.com/nostra13/Android-Universal-Image-Loader
and for drawable resources use this..
String imageUri = "drawable://" + R.drawable.image; // from drawables (only images, non-9patch)
I think these ways may help:
Put these images in server, then use Universal image loader to load it. Universal image loader have solved this problem. you can try this project https://github.com/dodola/Android-Universal-Image-Loader
If you have to put these images in res, I think you can implement you own image loader. In your Image loader, you have to cache the images in memory by use softreference. This is another problem.
I suggest you to use Aquery to download images. Just download the jarfile from this link
How to use :
AQuery _aq = new AQuery(youractivity context);
//fetch and set the image from internet, cache with file and memory
aq.id(R.id.your_imageview_object).image("http://www.vikispot.com/z/images/vikispot/android-w.png");

Android - ImageView does not display image. Nor does setImageResource()

I use an ImageView control as shown:
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/imgHangMan"
android:src="#drawable/hang0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
The above code displays the image in the Graphical Layout preview of the xml file. But on launching the app, I see no image. Also, changing the image using
imgHangMan = (ImageView)findViewById(R.id.imgHangMan);
imgHangMan.setImageResource(R.drawable.hang1);
This piece of code also does not work either. The image files are in .gif format and are in the drawable folder.
Any pointers ?
Natively ImageView doesnot support animated image. You have two options to show animated gif file
1) Use VideoView 2) Use ImageView. But Split the gif file into several parts and then apply animation to it.
Try this link-playing-gif-animation you will get the desired result.
Try this
image.setImageDrawable(getResources().getDrawable(R.drawable.hang1));
User this :
http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html
Go by this.

Why android resizes image?

I'm trying to change my application data source to the sdcard so that it doesn't take too much internal memory.
However, I had an Image that was dynamically loaded from the resource and displayed in an ImageView, now I load the image from the sdcard whenever I need it.
I had been using imageBox.setImageResource(imageID) and I changed to imageBox.setImageDrawable(imageDrawable).
The problem is that now Android resizes my image and it doesn't fit where it should.
Why is it resizing the image this way? And how can I stop it?
Thanks in advance :)
Add the tag android:scaleType="fitXY" to your ImageView's layout XML.
Ex.
<ImageView
... several settings ...
android:scaleType="fitXY"/>
Edit:
If your image is simply too big to fit inside the ImageView - it will have to do some kind of scaling. There are some other options as described in the API:
http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
Try the following for ImageView:
android:layout_height="fill_parent"
android:layout_width="fill_parent"
No Scale Type.
The ImageView Should be within Fixed Size (in dp) Parent View.

Categories

Resources