private void copy(Bitmap src, int x, int y, int width, int height, Bitmap dest) { int[] argbData = new int[width * height]; src.getARGB(argbData, 0, width, x, y, width, height); for (int tx = 0; tx < dest.getWidth(); tx += width) { for (int ty = 0; ty < dest.getHeight(); ty += height) { dest.setARGB(argbData, 0, width, tx, ty, width, height); } } }
public static Bitmap rotateImage(Bitmap oldB, int angle) { try { int w = oldB.getWidth(); int h = oldB.getHeight(); double angRad = (angle % 360) * (Math.PI / 180); Bitmap newB = new Bitmap(w, h); int[] oldD = new int[w * h]; int[] newD = new int[w * h]; oldB.getARGB(oldD, 0, w, 0, 0, w, h); int axisX = w / 2; int axisY = h / 2; for (int x = 0; x < oldD.length; x++) { int oldX = x % w; int oldY = x / w; int op = oldX - axisX; int adj = oldY - axisY; double oldT = MathUtilities.atan2(op, adj); double rad = Math.sqrt((op * op) + (adj * adj)); double newT = oldT + angRad; int newX = (int) MathUtilities.round((rad * Math.sin(newT)) + (double) axisX); int newY = (int) MathUtilities.round((rad * Math.cos(newT)) + (double) axisY); if (newX < 0 || newY < 0 || newX >= w || newY >= h) { newD[x] = 0x00000000; } else { newD[x] = oldD[(newY * w) + newX]; } } newB.setARGB(newD, 0, w, 0, 0, w, h); return newB; } catch (Exception e) { } return null; }
public void run() { int ask = -1; if (undo != null) ask = Dialog.ask( "What Filter?", new String[] {"GrayScale", "Negative", "Sephia", "Termal", "Undo Filter"}, 0); else ask = Dialog.ask( "What Filter?", new String[] {"GrayScale", "Negative", "Sephia", "Termal"}, 0); if (ask < 4) { undo = new int[gbr.getWidth() * gbr.getHeight()]; gbr.getARGB(undo, 0, gbr.getWidth(), 0, 0, gbr.getWidth(), gbr.getHeight()); FilterImg.doit(gbr, ask); } else if (ask == 4) { if (undo != null) { gbr.setARGB(undo, 0, gbr.getWidth(), 0, 0, gbr.getWidth(), gbr.getHeight()); undo = null; } } latar.invalidate(); }