How To Convert An Image Into Tattoo?
Am working the app for tattoolater in that i required to convert an image(which is taken from camera or selected from gallery)into tattoo... my requirement is like the following
Solution 1:
you need a difference filter:
1) you calc the horizontal difference (here you'll have vertical segments)
2) you calc the vertical difference (here, horizontal segments)
3) you OR the two maps, finding the outlines
4) recreate a Bitmap object, if you wish to do so
something like (EDITED):
int[] pixels;
int width = yourbitmap.getWidth();
int height = yourbitmap.getHeight();
yourbitmap.getPixels(pixels, 0, width, 0, 0, width, height);
// transform grayscaleint[] image = newint[width*height];
for (int y=0; y<height; y++)
for (int x=0; x<width; x++)
{
int pixel = image[y*width + x];
image[y*width + x] = (Color.red(pixel) + Color.green(pixel) + Color.blue(pixel))/3;
}
// calculate diff_x (vertical segments)int[] dx = newint[width*height];
for (int y=0; y<height; y++)
for (int x=0; x<width; x++)
dx[y*width + x] = (x==0 || y== 0 ? 0 : Math.abs(image[y*width + x] - image[y*width + x-1]));
// calculate diff_y (horizontal segments)int[] dy = newint[width*height];
for (int y=0; y<height; y++)
for (int x=0; x<width; x++)
dy[y*width + x] = (x==0 || y== 0 ? 0 : Math.abs(image[y*width+x] - image[(y-1)*width+x]));
// when the color intensity is higher than THRESHOLD, accept segment// you'll want a slider to change THRESHOLD valuesbool[] result = newbool[width*height];
constint THRESHOLD = 60; // adjust this valuefor (int y=0; y<height; y++)
for (int x=0; x<width; x++)
result[y*width + x] = (dx[y*width + x] > THRESHOLD || dy[y*width + x] > THRESHOLD);
Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
for (int y=0; y<height; y++)
for (int x=0; x<width; x++)
result.setPixel(x, y, result[y*width+x]? Color.Black : Color.White);
Solution 2:
You can use this:
publicstatic Bitmap ConvertToBlackAndWhite(Bitmap sampleBitmap) {
ColorMatrixbwMatrix=newColorMatrix();
bwMatrix.setSaturation(0);
finalColorMatrixColorFiltercolorFilter=newColorMatrixColorFilter(
bwMatrix);
BitmaprBitmap= sampleBitmap.copy(Bitmap.Config.ARGB_8888, true);
Paintpaint=newPaint();
paint.setColorFilter(colorFilter);
CanvasmyCanvas=newCanvas(rBitmap);
myCanvas.drawBitmap(rBitmap, 0, 0, paint);
return doBlackWhiteImage(rBitmap);
}
publicstatic BlackWhiteImage doBlackWhiteImage(Bitmap myBitmap) {
int[] allpixels = newint[myBitmap.getHeight() * myBitmap.getWidth()];
myBitmap.getPixels(allpixels, 0, myBitmap.getWidth(), 0, 0,
myBitmap.getWidth(), myBitmap.getHeight());
for (inti=0; i < myBitmap.getHeight() * myBitmap.getWidth(); i++) {
if (allpixels[i] == Color.BLACK)
// do somethingelseif (allpixels[i] == Color.TRANSPARENT)
// do somethingelseif (allpixels[i] == Color.WHITE)
// do somethingelse {
allpixels[i] = Color.WHITE;
}
}
myBitmap.setPixels(allpixels, 0, myBitmap.getWidth(), 0, 0,
myBitmap.getWidth(), myBitmap.getHeight());
return myBitmap;
}
Post a Comment for "How To Convert An Image Into Tattoo?"