i have Gridview that display Image from internet using universal-image-loader
i want when i click on image in gridview
show up in full screen
here is my simple code :
MainActivity
Photoist.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,int pos, long id) {
// String url = mAdapter.getItem(pos).getImgUrl();
GridView lv = (GridView) parent;
ImageView SelectedImage = (ImageView) parent.getChildAt(pos-lv.getFirstVisiblePosition()).findViewById(R.id.iconImg);
SelectedImage.buildDrawingCache();
Bitmap myimage = SelectedImage.getDrawingCache();
Intent intent = new Intent(getActivity(),FullScreenImageView.class);
intent.putExtra("MyImageIntent", myimage);
startActivity(intent);
}
});
FullScreenImageView.Class
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
ImageView Fullscreen = (ImageView) findViewById(R.id.imgDisplay);
Bitmap Image = (Bitmap) getIntent().getExtras().get("MyImageIntent");
Fullscreen.setImageBitmap(Image);
}
The Error in this Code :
Fullscreen.setImageBitmap(Image);
i hope someone can help
and i have 1 more question
how i can make the FullScreenImage Swipe/Slide . i mean if i slide image left it show next image, and i slide it right show previews image .
-sorry for my bad english, and thanks
Edit:
Try this when getting the Bitmap from your ImageView:
Bitmap image = ((BitmapDrawable)SelectedImage.getDrawable()).getBitmap();
Bitmap class implements parcelable, which means that it's instances can be stored in a parcel.
Parcel by the way is just androids way of serialization.
Change
Bitmap image = (Bitmap) getIntent().getExtras().get("MyImageIntent");
to
Bitmap image = (Bitmap) getIntent().getParcelableExtra("MyImageIntent");
For the slide part you want to create a ViewPager which was designed for exactly that.
Related
Shopping Flyer A viewpager contain a firebase image.This image contain many small different images.When I touch a small image I have to display to another activity.how to proceed to achieve this ?
Use a GridLayout, with ImageView children. Use the onClickListener of the ImageView when they were added to the GridLayout to determine which image was clicked.
You don't need to know the coordinates of the image. Because the ImageView has its own space.
GridLayout gridLayout;
ArrayList<MyImage> myImages; // MyImage model should contain the image and information about the product
for (MyImage myImage : myImages) {
ImageView imageView = new ImageView(this);
imageView.setImageBitmap(myImage.getImageBitmap());
imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// start your details activity here
}
});
gridLayout.addView(imageView);
}
How avoid the 40% of CPU usage and 70MB of RAM (start with 10MB) when a thumb is touched and the function start?
This is the scenario:
I have a ListView that can contains text or image.
The user can take pictures and that pictures are saved to sdcard0 and loaded by path to the relative ImageView.
I have some problem with the performance of this.
Adapter that save image or text and put it into a listview:
PS: i try with the ViewHolder for optimize the listview but i get some problem with the image loading with Picasso so i removed it!
#Override
public View getView(int position, View convertView, ViewGroup parent){
LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.evento_list_view_line, null);
ImageView img = (ImageView)convertView.findViewById(R.id.compiti_imageView);
TextView compito = (TextView)convertView.findViewById(R.id.compiti_text);
Compiti m = getItem(position);
if(m.getTestoCompito() != null){
compito.setText(m.getTestoCompito());
//Invisibile e non presente nel layout
img.setVisibility(View.GONE);
}else if(m.getPathFoto() != null){
//load img
Picasso.with(getContext())
.load(m.getPathFoto())
.resize(200, 200)
.centerCrop()
.into(img);
//Set the tag for retrieve the path of image from listview
img.setTag(m.getPathFoto());
}
return convertView;
}
As you can see i use the setTag(ImgPath) for retrieve the path from ImageView.
This is how i retrieve touched image if the image is in the ImageView:
// ListView Item Click Listener
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ImageView image_to_zoom = (ImageView) view.findViewById(R.id.compiti_imageView);
if (image_to_zoom.getDrawable() != null) {
//Image IN
String path = image_to_zoom.getTag().toString();
zoomImageFromThumb(image_to_zoom, path);
} else {
//Imane nope
Toast.makeText(getApplicationContext(), "No photo here!" , Toast.LENGTH_LONG).show();
}
}
});
// Retrieve and cache the system's default "short" animation time.
mShortAnimationDuration = getResources().getInteger(
android.R.integer.config_shortAnimTime);
I found the method zoomImageFromThumb(image_to_zoom, path); from google.developer and I made some changes because the original code take images from R.resources and i need to take image from memory (folder Pictures).
My change:
private void zoomImageFromThumb(final View thumbView, String imagePath) {
// If there's an animation in progress, cancel it
// immediately and proceed with this one.
if (mCurrentAnimator != null) {
mCurrentAnimator.cancel();
}
// Load the high-resolution "zoomed-in" image.
final ImageView expandedImageView = (ImageView) findViewById(
R.id.expanded_image);
//expandedImageView.setImageResource(imageResId);
Picasso.with(this)
.load(imagePath)
.into(expandedImageView);
If i set the path manually without the method getTag() the app load very fast the touched image, but with the method getTag() for retrieve the path of the image the app is very slow to load the zoom of touched image.
Some suggestion or help?
There is another way for retrieve the path of an image in a ImageView?
I'm trying to load in part of a tall image into a scrollable imageview (imageview inside a scrollview).
It works with smaller images but if the images is bigger than 2048x2048 the app will crash due to open gl out of memory.
I can load part of the image with this:
private Bitmap decodeBitmapRegion(InputStream in, Rect region) {
BitmapRegionDecoder decoder = null;
try {
decoder = BitmapRegionDecoder.newInstance(in, false);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
region.right = decoder.getWidth();
Bitmap reg = decoder.decodeRegion(region, null);
return reg;
}
Where the rectangle can be something like (0,0,DisplayWidth,800).
That works in most cases since i'm using the imageview to let the user crop a part of the image and save it as a coveriamge.The imageview has the same width as the display and the height of 400 dp.
So the image the user saves will be the same width as the orginal but only 400 dp's tall.
Is there anyway to make it possible for the user to scroll all the way to the bottom of the orginal image?
How does webview load images that are bigger than 2048x2048?
Here's one thought.
Imagine your image broken into rows of bands. Use a ListView to display the bands. A ListView uses an adapter. In adapter.getView(), you use the decoder to load the appropriate band.
The ListView already does "recycling". So, it more-or-less only holds enough rows to fill the screen.
This technique should work well if your images aren't too wide. If they are, and it's not tall enough to occupy more than one screen height, you'll still have the same memory problems. A more complicated solution would be to use some sort of grid view, but then you'll have to do your own view recycling. Not too difficult, but harder than using ListView.
I managed to get the functionality I wanted. But i don't think this is the best solution?
I loaded the image into a webview and then i took a screenshot of the visible part of the webview. After that i can save that bitmap and do whatever i want to it.
But there must be a better way to do this than to use a webview to show the original image?
Anyway here is what I did:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button1);
imgView = (ImageView) findViewById(R.id.imageview);
webView = (WebView) findViewById(R.id.webview);
webView.loadUrl("file:///android_asset/test.jpg");
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
imgView.setImageBitmap(getBitmapForVisibleRegion(webView));
}
});
}
public static Bitmap getBitmapForVisibleRegion(WebView webview) {
Bitmap returnedBitmap = null;
webview.setDrawingCacheEnabled(true);
returnedBitmap = Bitmap.createBitmap(webview.getDrawingCache());
webview.setDrawingCacheEnabled(false);
return returnedBitmap;
}
I implemented lazy ListView adapter to display the images along with text from internet in Listview.Now I want to get the Bitmap of image when particular ListItem clicked and want to display it in a ImageView,But I am unable to get the Bitmap from the image.I am using this logic in OnItemClickListener for ListView:-
View imageView1 = listView1.getChildAt(position);
ImageView imageView3 = (ImageView) imageView1.findViewById(R.id.image);
Bitmap b;
imageView3.setDrawingCacheEnabled(true);
imageView3.buildDrawingCache();
b = ((BitmapDrawable) imageView3.getDrawable()).getBitmap();
car_image_detail.setImageBitmap(b);
But getting NullPointerException sometimes.Can anyone please help me out..?
Please use my code. I am getting the image from the listview when a particular item is clicked and setting it to another imageview.
//Code in listview itemclick listener
final ImageView imageView = (ImageView) view.findViewById(R.id.icon);
final BitmapDrawable bitmapDrawable = (BitmapDrawable) imageView.getDrawable();
final Bitmap yourBitmap = bitmapDrawable.getBitmap();
show.setImageBitmap(yourBitmap); // show is another imageview
I followed another StackOverflow tutorial where you can capture a bitmap from the camera and set it to your image view. The issue I am having is that the picture that is returned is very small and does not fill the rest of the screen. In my XML I do the following...
<ImageView
android:id="#+id/imgview"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
If I change to "fill_parent" I get a larger image, but my question now is how would I go about getting the actual size image and putting it on a scrollable (in both the x and y directions) view container.
Thanks!
BTW, here is the code for capturing the Bitmap from the camera...
public class MainActivity extends Activity implements OnClickListener
{
private ImageView imageView;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("matt","1");
Button b = (Button)this.findViewById(R.id.btn);
imageView = (ImageView)this.findViewById(R.id.imgview);
b.setOnClickListener(this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
#Override
public void onClick(View v)
{
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent,1888);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(requestCode == 1888)
{
Log.d("matt", "3.a");
Bitmap photo = (Bitmap) data.getExtras().get("data");
Log.d("matt", "3.b");
imageView.setImageBitmap(photo);
Log.d("matt", "3.c");
}
}
If you need the dimensions of the image being captured then you can use:
int height = photo.getHeight();
int width = photo.getWidth();
Otherwise, if you would like to find out the size of the image captured (in megabytes) then please refer to my answer to this question: https://stackoverflow.com/a/11846455/1512836
[EDIT] - Please check this for scrolling an image view: Images in ScrollView in android
The caller may pass an extra EXTRA_OUTPUT to control where this image will be written. If the EXTRA_OUTPUT is not present, then a small sized image is returned as a Bitmap object in the extra field. This is useful for applications that only need a small image. If the EXTRA_OUTPUT is present, then the full-sized image will be written to the Uri value of EXTRA_OUTPUT.