I have an example code that comes with Android that distorts a bitmap (Bitmapmesh.java). I want the circle to be placed on my image, which gives a fisheye effect. I am new to android and especially to graphics, is it possible to create this effect in a bitmapmesh sample?
I'm not sure where to start, so any pointers would be appreciated. Can someone give me a high-level view of what is connected, for example, I would like to put a circle on the image first. I placed the buttons above the images before they seemed to float, this was done using a relative layout and then adding child buttons. What am I doing now is different and is likely to be related to calling some onDraw method? I also have an algorithm that performs distortion, I'm just not sure how to apply this to the image.
Below is the bitmapmesh code. Can someone tell me where to start, even if he first places a circle on the image, then I can cope with the implementation of the effect.
thanks mate
import java.io.BufferedInputStream; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.InputStream;
import android.content.Context; import android.graphics .; import android.os.Bundle; import android.os.Environment; import android.view .; import android.util.FloatMath;
public class BitMapFishEye extends GraphicsActivity {
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new SampleView(this)); } private static class SampleView extends View { private static final int WIDTH = 20; private static final int HEIGHT = 20; private static final int COUNT = (WIDTH + 1) * (HEIGHT + 1); private final Bitmap mBitmap; private final float[] mVerts = new float[COUNT*2]; private final float[] mOrig = new float[COUNT*2]; private final Matrix mMatrix = new Matrix(); private final Matrix mInverse = new Matrix(); private File tempFile; private byte[] imageArray; private static void setXY(float[] array, int index, float x, float y) { array[index*2 + 0] = x; array[index*2 + 1] = y; } public SampleView(Context context) { super(context); setFocusable(true); tempFile = new File(Environment.getExternalStorageDirectory(). getAbsolutePath() + "/"+"image.jpg"); imageArray = new byte[(int)tempFile.length()]; try{ InputStream is = new FileInputStream(tempFile); BufferedInputStream bis = new BufferedInputStream(is); DataInputStream dis = new DataInputStream(bis); int i = 0; while (dis.available() > 0) { imageArray[i] = dis.readByte(); i++; } dis.close(); } catch (Exception e) { e.printStackTrace(); } BitmapFactory.Options bfo = new BitmapFactory.Options(); bfo.inSampleSize = 5; mBitmap = BitmapFactory.decodeByteArray(imageArray, 0, imageArray.length, bfo); float w = mBitmap.getWidth(); float h = mBitmap.getHeight();
}
source share