Hi all, I'm having trouble displaying an oversized scrolling image. I accomplished this originally by creating the custom class below to replace the standard ImageView. My original large image was a png that was a little over 1000x1000 in resolution and about 722kb in size. For that image, the class below worked flawlessley. But now I need to do the same thing with a MUCH larger image and I'm wondering if this is not the best way to go about it. My new image is about 5000x5000 and I've produced varying versions from png's that were up to 6MB to jpg's that were 1.5MB. All of these images cause my app to crash instantly without any changes to the code (besides referencing the larger image). The important thing I need to do is be able to scroll and zoom, and I'm starting to think the only way I'm going to get this working is to slice my image up and create some sort of scrolling GridView inside an AbsoluteLayout, that only loads the slices that are displayed on screen. This is a bit more work than I was hoping to put into this app, but can anyone give me any advice on which direction I should be heading?
Below is my ScrollingImageView class for reference. It works flawlessly if the image is not too big, so feel free to use it however you'd like. Thanks in advance, G import android.content.Context; import android.view.GestureDetector; import android.view.MotionEvent; import android.view.GestureDetector.OnGestureListener; import android.widget.AbsoluteLayout; import android.widget.ImageView; import android.widget.LinearLayout; public class ScrollingImageView extends AbsoluteLayout implements OnGestureListener { private GestureDetector mGestureDetector; private ImageView mImageView; public ScrollingImageView(Context context, int imageResId, int imageWidth, int imageHeight) { super(context); mImageView = new ImageView(context); mImageView.setImageResource(imageResId); this.addView(mImageView, new LinearLayout.LayoutParams(imageWidth, imageHeight)); mGestureDetector = new GestureDetector(this); mGestureDetector.setIsLongpressEnabled(false); } @Override public boolean onDown(MotionEvent e) { return false; } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // TODO Auto-generated method stub return false; } @Override public void onLongPress(MotionEvent e) { } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { int scrollWidth = mImageView.getWidth() - this.getWidth(); if ((this.getScrollX() >= 0) && (this.getScrollX() <= scrollWidth) && (scrollWidth > 0)) { int moveX = (int)distanceX; if (((moveX + this.getScrollX()) >= 0) && ((Math.abs(moveX) + Math.abs(this.getScrollX())) <= scrollWidth)) { this.scrollBy(moveX, 0); } else { if (distanceX >= 0) { this.scrollBy(scrollWidth - Math.max(Math.abs (moveX), Math.abs(this.getScrollX())), 0); } else { this.scrollBy(-Math.min(Math.abs(moveX), Math.abs (this.getScrollX())), 0); } } } int scrollHeight = mImageView.getHeight() - this.getHeight(); if ((this.getScrollY() >= 0) && (this.getScrollY() <= scrollHeight) && (scrollHeight > 0)) { int moveY = (int)distanceY; if (((moveY + this.getScrollY()) >= 0) && ((Math.abs(moveY) + Math.abs(this.getScrollY())) <= scrollHeight)) { this.scrollBy(0, moveY); } else { if (distanceY >= 0) { this.scrollBy(0, scrollHeight - Math.max(Math.abs (moveY), Math.abs(this.getScrollY()))); } else { this.scrollBy(0, -Math.min(Math.abs(moveY), Math.abs (this.getScrollY()))); } } } return true; } @Override public void onShowPress(MotionEvent e) { // TODO Auto-generated method stub } @Override public boolean onSingleTapUp(MotionEvent e) { // TODO Auto-generated method stub return false; } @Override public boolean dispatchTouchEvent(MotionEvent ev) { mGestureDetector.onTouchEvent(ev); return true; } public void zoomIn() { int h = mImageView.getHeight(); int w = mImageView.getWidth(); h *= 2; w *= 2; this.removeAllViews(); this.addView(mImageView, new LinearLayout.LayoutParams(w, h)); } public void zoomOut() { this.scrollTo(0, 0); int h = mImageView.getHeight(); int w = mImageView.getWidth(); h /= 2; w /= 2; this.removeAllViews(); this.addView(mImageView, new LinearLayout.LayoutParams(w, h)); } } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---