Zoom Image !!


HOME ยป VB & VBnet

Hello everybody!
I’m trying to create a program in which the user has the ability to move the image with mouse click and ability to zoom in and out by scrolling the mouse wheel. If the user wants to return to the original image size and position, it will be possible with a click of a button.
I was able to do everything said above for the exception that after the user clicks on the reset button and zooms again, the previous size of the image is shown with the position where it was before the reset button was pressed.
How would it be possible to fix this without recoding the whole thing?
And also can you tell me how to make the image to zoom in to center of the


Related to : Zoom Image !!
Zoom In and zoom out but no loss in resolution of the Image
VB & VBnet
Hi there,
I am currently in the process of making a flash movie. In the first section of the movie I have three scrollers and there are buttons beside these scrollers to choose which components of the scrollers he/she wants.
Below these scrollers I have a button directing to the next page to see the sum of the three scrollers ie. the final result.
The final result image is rather small and I want to allow the user to see the image in more detail.
I have a zoom piece of code and it doesn't seem to work for me.
Can anyone help me out on this please?
Thanks
Zoom In and zoom out but no loss in resolution of the Image !
VB & VBnet
Hi there,
I am currently in the process of making a flash movie. In the first section of the movie I have three scrollers and there are buttons beside these scrollers to choose which components of the scrollers he/she wants.
Below these scrollers I have a button directing to the next page to see the sum of the three scrollers ie. the final result.
The final result image is rather small and I want to allow the user to see the image in more detail.
I have a zoom piece of code and it doesn't seem to work for me.
Can anyone help me out on this please?
Thanks
Android : Zoom Image And Draw line on image with current zoom
VB & VBnet

enter image
description hereenter image description here I am using ImageView support zooming.Right now I am extending the ImageView so i can draw on canvas . Currently i Have setImageResource setting a drawable and In onDraw(canvas); i am drawing some line over a path then drawing that over the canvas.

The problem is when i try zooming, the image zooms perfectly but the drawing that was drawn over the canvas is not zooming. it just stays in place.

Steps
-  First screen Image view
- Zoom Imageview.
- Now Draw on Image like signature,line,circle etc
- Then when zoom out at that time it should be display when you draw
object. 

import java.io.ByteArrayOutputStream;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.FloatMath;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;

public class ScaleImageView extends ImageView implements
OnTouchListener {

static final float STROKE_WIDTH = 10f;
static final float HALF_STROKE_WIDTH = STROKE_WIDTH / 2;

float lastTouchX;
float lastTouchY;
final RectF dirtyRect = new RectF();

private Context mContext;
private float MAX_SCALE = 2f;

private static Matrix mMatrix;
private final float[] mMatrixValues = new float[9];

// display width height.
private int mWidth;
private int mHeight;

private int mIntrinsicWidth;
private int mIntrinsicHeight;

private float mScale;
private float mMinScale;

private float mPrevDistance;
private boolean isScaling;

private int mPrevMoveX;
private int mPrevMoveY;
private GestureDetector mDetector;

Paint paint = new Paint();
Path path = new Path();

public static int imageheight, imagewidth;

String TAG = "ScaleImageView";

public ScaleImageView(Context context, AttributeSet attr) {
    super(context, attr);
    this.mContext = context;
    initialize();
}

public ScaleImageView(Context context) {
    super(context);
    this.mContext = context;
    initialize();
}

private void resetDirtyRect(float eventX, float eventY) {
    dirtyRect.left = Math.min(lastTouchX, eventX);
    dirtyRect.right = Math.max(lastTouchX, eventX);
    dirtyRect.top = Math.min(lastTouchY, eventY);
    dirtyRect.bottom = Math.max(lastTouchY, eventY);
}

@Override
public void setImageBitmap(Bitmap bm) {
    super.setImageBitmap(bm);
    this.initialize();
}

@Override
public void setImageResource(int resId) {
    super.setImageResource(resId);
    this.initialize();
}

private void initialize() {
    this.setScaleType(ScaleType.MATRIX);
    this.mMatrix = new Matrix();
    Drawable d = getDrawable();
    if (d != null) {
        mIntrinsicWidth = d.getIntrinsicWidth();
        mIntrinsicHeight = d.getIntrinsicHeight();
        setOnTouchListener(this);
    }
    mDetector = new GestureDetector(mContext,
            new GestureDetector.SimpleOnGestureListener() {
                @Override
                public boolean onDoubleTap(MotionEvent e) {
                    maxZoomTo((int) e.getX(), (int) e.getY());
                    cutting();
                    return super.onDoubleTap(e);
                }
            });

}

@Override
protected boolean setFrame(int l, int t, int r, int b) {
    mWidth = r - l;
    mHeight = b - t;

    mMatrix.reset();
    int r_norm = r - l;
    mScale = (float) r_norm / (float) mIntrinsicWidth;

    int paddingHeight = 0;
    int paddingWidth = 0;
    // scaling vertical
    if (mScale * mIntrinsicHeight > mHeight) {
        mScale = (float) mHeight / (float) mIntrinsicHeight;
        mMatrix.postScale(mScale, mScale);
        paddingWidth = (r - mWidth) / 2;
        paddingHeight = 0;
        // scaling horizontal
    } else {
        mMatrix.postScale(mScale, mScale);
        paddingHeight = (b - mHeight) / 2;
        paddingWidth = 0;
    }
    mMatrix.postTranslate(paddingWidth, paddingHeight);

    setImageMatrix(mMatrix);
    mMinScale = mScale;
    zoomTo(mScale, mWidth / 2, mHeight / 2);
    cutting();
    return super.setFrame(l, t, r, b);
}

protected float getValue(Matrix matrix, int whichValue) {
    matrix.getValues(mMatrixValues);
    return mMatrixValues[whichValue];
}

protected float getScale() {
    return getValue(mMatrix, Matrix.MSCALE_X);
}

public float getTranslateX() {
    return getValue(mMatrix, Matrix.MTRANS_X);
}

protected float getTranslateY() {
    return getValue(mMatrix, Matrix.MTRANS_Y);
}

protected void maxZoomTo(int x, int y) {
    if (mMinScale != getScale() && (getScale() - mMinScale)
> 0.1f) {
        // threshold 0.1f
        float scale = mMinScale / getScale();
        zoomTo(scale, x, y);
    } else {
        float scale = MAX_SCALE / getScale();
        zoomTo(scale, x, y);
    }
}

public void zoomTo(float scale, int x, int y) {
    if (getScale() * scale < mMinScale) {
        return;
    }
    if (scale >= 1 && getScale() * scale > MAX_SCALE) {
        return;
    }
    mMatrix.postScale(scale, scale);
    // move to center
    mMatrix.postTranslate(-(mWidth * scale - mWidth) / 2,
            -(mHeight * scale - mHeight) / 2);

    // move x and y distance
    mMatrix.postTranslate(-(x - (mWidth / 2)) * scale, 0);
    mMatrix.postTranslate(0, -(y - (mHeight / 2)) * scale);
    setImageMatrix(mMatrix);
}

public void cutting() {
    int width = (int) (mIntrinsicWidth * getScale());
    int height = (int) (mIntrinsicHeight * getScale());

    imagewidth = width;
    imageheight = height;

    if (getTranslateX() < -(width - mWidth)) {
        mMatrix.postTranslate(-(getTranslateX() + width - mWidth), 0);
    }
    if (getTranslateX() > 0) {
        mMatrix.postTranslate(-getTranslateX(), 0);
    }
    if (getTranslateY() < -(height - mHeight)) {
        mMatrix.postTranslate(0, -(getTranslateY() + height -
mHeight));
    }
    if (getTranslateY() > 0) {
        mMatrix.postTranslate(0, -getTranslateY());
    }
    if (width < mWidth) {
        mMatrix.postTranslate((mWidth - width) / 2, 0);
    }
    if (height < mHeight) {
        mMatrix.postTranslate(0, (mHeight - height) / 2);
    }
    setImageMatrix(mMatrix);
}

private float distance(float x0, float x1, float y0, float y1) {
    float x = x0 - x1;
    float y = y0 - y1;
    return FloatMath.sqrt(x * x + y * y);
}

private float dispDistance() {
    return FloatMath.sqrt(mWidth * mWidth + mHeight * mHeight);
}

public void clear() {
    path.reset();
    invalidate();
}

public static void save() {

    Bitmap returnedBitmap = Bitmap.createBitmap(
            ScaleImageViewActivity.imageview.getWidth(),
            ScaleImageViewActivity.imageview.getHeight(),
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(returnedBitmap);

    Drawable bgDrawable =
ScaleImageViewActivity.imageview.getDrawable();

    if (bgDrawable != null)
        bgDrawable.draw(canvas);
    else
        canvas.drawColor(Color.WHITE);

    ScaleImageViewActivity.imageview.draw(canvas);

    ByteArrayOutputStream bs = new ByteArrayOutputStream();
    returnedBitmap.compress(Bitmap.CompressFormat.PNG, 50, bs);

    Bitmap FinalBitmap =
BitmapFactory.decodeByteArray(bs.toByteArray(), 0,
            bs.toByteArray().length);

    ScaleImageViewActivity.imageview.setImageBitmap(FinalBitmap);
    // ScaleImageViewActivity.imageview.setImageMatrix(mMatrix);

}

@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (!ScaleImageViewActivity.flag) {

        if (mDetector.onTouchEvent(event)) {
            return true;
        }
        int touchCount = event.getPointerCount();
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_POINTER_1_DOWN:
        case MotionEvent.ACTION_POINTER_2_DOWN:
            if (touchCount >= 2) {
                float distance = distance(event.getX(0),
event.getX(1),
                        event.getY(0), event.getY(1));
                mPrevDistance = distance;
                isScaling = true;
            } else {
                mPrevMoveX = (int) event.getX();
                mPrevMoveY = (int) event.getY();
            }
        case MotionEvent.ACTION_MOVE:
            if (touchCount >= 2 && isScaling) {
                float dist = distance(event.getX(0), event.getX(1),
                        event.getY(0), event.getY(1));
                float scale = (dist - mPrevDistance) / dispDistance();
                mPrevDistance = dist;
                scale += 1;
                scale = scale * scale;
                zoomTo(scale, mWidth / 2, mHeight / 2);
                cutting();
            } else if (!isScaling) {
                int distanceX = mPrevMoveX - (int) event.getX();
                int distanceY = mPrevMoveY - (int) event.getY();
                mPrevMoveX = (int) event.getX();
                mPrevMoveY = (int) event.getY();
                mMatrix.postTranslate(-distanceX, -distanceY);
                cutting();
            }
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_POINTER_UP:
        case MotionEvent.ACTION_POINTER_2_UP:
            if (event.getPointerCount() <= 1) {
                isScaling = false;
            }
            break;
        }
    } else {
        float eventX = event.getX();
        float eventY = event.getY();

        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            path.moveTo(eventX, eventY);
            lastTouchX = eventX;
            lastTouchY = eventY;
            return true;

        case MotionEvent.ACTION_MOVE:

        case MotionEvent.ACTION_UP:

            resetDirtyRect(eventX, eventY);
            int historySize = event.getHistorySize();
            for (int i = 0; i < historySize; i++) {
                float historicalX = event.getHistoricalX(i);
                float historicalY = event.getHistoricalY(i);
                path.lineTo(historicalX, historicalY);
            }
            path.lineTo(eventX, eventY);
            break;
        }

        invalidate((int) (dirtyRect.left - HALF_STROKE_WIDTH),
                (int) (dirtyRect.top - HALF_STROKE_WIDTH),
                (int) (dirtyRect.right + HALF_STROKE_WIDTH),
                (int) (dirtyRect.bottom + HALF_STROKE_WIDTH));

        lastTouchX = eventX;
        lastTouchY = eventY;
    }
    return true;
}

@Override
protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.onDraw(canvas);
    if (ScaleImageViewActivity.flag)
        canvas.drawPath(path, paint);
}

@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View v, MotionEvent event) {
    return super.onTouchEvent(event);
}

}

//ACTIVITY

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ScaleImageViewActivity extends Activity implements
OnClickListener {

Button btndraw, btnzoom, btnsave;

public static ScaleImageView imageview;
public static boolean flag = true;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    initwidget();
}

private void initwidget() {

    imageview = (ScaleImageView) findViewById(R.id.image);

    btnsave = (Button) findViewById(R.id.activity_main_save);
    btndraw = (Button) findViewById(R.id.activity_main_zoom_draw);
    btnzoom = (Button) findViewById(R.id.activity_main_zoom_zoom);

    btndraw.setOnClickListener(this);
    btnzoom.setOnClickListener(this);
    btnsave.setOnClickListener(this);
}

@Override
public void onClick(View arg0) {
    // TODO Auto-generated method stub
    if (btndraw.equals(arg0)) {
        flag = true;
    } else if (btnzoom.equals(arg0)) {
        flag = false;
    } else if (btnsave.equals(arg0)) {
        ScaleImageView.save();
    }
}
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <Button
        android:id="@+id/activity_main_zoom_zoom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Zoom" />

    <Button
        android:id="@+id/activity_main_zoom_draw"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Draw" />

    <Button
        android:id="@+id/activity_main_save"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Save" />
</LinearLayout>

<com.matabii.dev.scaleimageview.ScaleImageView
    android:id="@+id/image"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:src="@drawable/sample" />

</LinearLayout>

How to zoom in and zoom out an image window phone 8
VB & VBnet

I want zoom an image in canvas use Touch.FrameReported code bellow:

//XAML
<Canvas x:Name="cvWhiteBoard" Grid.Row="1" Background="White"
Tap="cvWhiteBoard_Tap" />
public uc_Paint()
        {
            InitializeComponent();

            Touch.FrameReported += new
TouchFrameEventHandler(Touch_FrameReported);
        }
        private Point point1;
        private Point point2;
        private double lengthLineOld;
        private FrameworkElement objCureent;
//Touch_FrameReported event
 void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            int pointsNumber = e.GetTouchPoints(cvWhiteBoard).Count;
            double lengthLine = 0;
            TouchPointCollection pointCollection =
e.GetTouchPoints(cvWhiteBoard);

            if (objCureent != null && pointsNumber == 2)
            {
                point1 = pointCollection[0].Position;
                point2 = pointCollection[1].Position;


                if (pointCollection[0].Action == TouchAction.Move)
                {
                    lengthLine = Math.Sqrt(Math.Pow((point1.X -
point2.X), 2) + Math.Pow((point1.Y - point2.Y), 2));

                    if (lengthLine > lengthLineOld)
                    {
                        int result = Convert.ToInt32(lengthLine -
lengthLineOld);
                        if (result > 15)
                        {
                            if (objCureent.ActualWidth <
cvWhiteBoard.ActualWidth && objCureent.ActualHeight <
cvWhiteBoard.ActualHeight)
                            {
                                objCureent.Width =
objCureent.ActualWidth + result;
                                objCureent.Height =
objCureent.ActualHeight + result;

                                st.Width = objCureent.Width;
                                st.Height = objCureent.Height;
                            }
                        }

                    }
                    else if (lengthLine < lengthLineOld)
                    {
                        int result = Convert.ToInt32(lengthLineOld -
lengthLine);
                        if (result > 15)
                        {
                            if (objCureent.ActualWidth > 100
&& objCureent.ActualHeight > 100)
                            {
                                objCureent.Width =
objCureent.ActualWidth - result > 50 ? objCureent.ActualWidth -
result : objCureent.ActualWidth;
                                objCureent.Height =
objCureent.ActualHeight - result > 50 ? objCureent.ActualHeight -
result : objCureent.ActualHeight;
                                st.Width = objCureent.Width;
                                st.Height = objCureent.Height;

                            }
                        }
                    }

                    lengthLineOld = lengthLine;
                }
            }
        }

But when i running application and debug display: An unhandled exception of type 'System.ArgumentException' occurred in System.Windows.ni.dll

Additional information: Value does not fall within the expected range. How to fix it?


Google Maps API v3 - canvas/image zoom instead of proper map zoom
VB & VBnet

I finally made exactly what I want, but with "minor bug" I cant locate.

This code sets initialized viewport as strictBounds with smooth drag along edges (thanks to SO tip). There is custom zoom-in and controled zoom-out directed to default(means center of the map at minZoom) position.

Graphic issue occurs when cursor position on map doesn't change and I do mouse scroll-in + mouse-out twice in a row. Instead of map zoom, there is "bugged" image/canvas zoom - double size of markers and enlarged map canvas bellow - all ofcourse blurred/rasterized. Once I move with cursor, it redraws and shows properly. Any idea whats wrong? Thanks!

            /*baseZoom=7,minLevel=7*/
            var newLat, newLng,allowedBounds=0,boundLimits,
lastValidCenter,lastZoom,baseCenter;
            google.maps.event.addListener(map, 'bounds_changed',
function() {
                if (allowedBounds==0) {
                    allowedBounds = map.getBounds();
                    /*protoze zobrazovane okno je male, rozsireni
oblasti pro infowindow - pri lepsim zoomu byt nemusi*/
                    allowedBounds.extend(new
google.maps.LatLng(allowedBounds.getNorthEast().lat()+0.7,allowedBounds.getNorthEast().lng()+0.7));
                    allowedBounds.extend(new
google.maps.LatLng(allowedBounds.getSouthWest().lat()-0.7,allowedBounds.getSouthWest().lng()-0.7));
                    /*------*/
                    boundLimits = {
                        maxLat : allowedBounds.getNorthEast().lat(),
                        maxLng : allowedBounds.getNorthEast().lng(),
                        minLat : allowedBounds.getSouthWest().lat(),
                        minLng : allowedBounds.getSouthWest().lng()
                    };
                    lastValidCenter = map.getCenter();
                    baseCenter = map.getCenter();
                    lastZoom=baseZoom;
                }
                var center = map.getCenter();
                var zoom = map.getZoom();
                newLat = lastValidCenter.lat();
                newLng = lastValidCenter.lng();
                var a = map.getBounds().getNorthEast();
                var b = map.getBounds().getSouthWest();
                if
(allowedBounds.contains(a)&&allowedBounds.contains(b))
lastValidCenter = center;             
                else {
                    if(b.lng() > boundLimits.minLng &&
a.lng() < boundLimits.maxLng) newLng = center.lng();
                    if(b.lat() > boundLimits.minLat &&
a.lat() < boundLimits.maxLat) newLat = center.lat();
                }
                if (zoom<lastZoom) {
                    var scale=zoom-(baseZoom-1);
                    if (newLng>baseCenter.lng())
newLng=newLng-((newLng-baseCenter.lng())/scale);
                    if (newLng<baseCenter.lng())
newLng=newLng+((baseCenter.lng()-newLng)/scale);
                    if (newLat>baseCenter.lat())
newLat=newLat-((newLat-baseCenter.lat())/scale);
                    if (newLat<baseCenter.lat())
newLat=newLat+((baseCenter.lat()-newLat)/scale);
                }
                if
((lastValidCenter==center&&zoom<lastZoom)||lastValidCenter!=center)
                    map.panTo(new google.maps.LatLng(newLat, newLng));
                lastZoom=zoom;
            });

Rotate ,zoom-in and zoom-out a image in HTML5
VB & VBnet

How to rotate ,zoom-in and zoom-out a image in HTML5 canvas using mouse or touch . The logic is as the two finger stretches apart the image zooms in and as the finger moves together the image zooms out.Similarly when i move two fingers in circular manner in opposite direction then it must rotate like in google maps.



Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .