2012-03-23 2 views
1

나는 두 개의 비트 맵 topBitmap과 bottomBitmap을 가지고 있으며 안드로이드에서 색상 피하기를 사용하여 두 비트 맵을 혼합해야합니다. PorterDuffXfermode에서 색상 피하기를 찾을 수 없습니다. 캔버스를 사용하지 않고 그것을 할 수있는 방법이 있습니까?색상 닷지 블렌드 비트 맵

안드로이드에서 색상 닷지 모드를 사용하여 두 비트 맵을 혼합하는 방법을 알려주세요. 미리 감사드립니다.

답변

3

안녕하세요, 저는이 게시물을 어딘가에서 찾았습니다. 이 방법은 두 가지 이미지를 소요 및 색상을 사용하여 하나 개의 이미지를 만들 닷지

public Bitmap ColorDodgeBlend(Bitmap source, Bitmap layer) { 
      Bitmap base = source.copy(Config.ARGB_8888, true); 
      Bitmap blend = layer.copy(Config.ARGB_8888, false); 

      IntBuffer buffBase = IntBuffer.allocate(base.getWidth() * base.getHeight()); 
      base.copyPixelsToBuffer(buffBase); 
      buffBase.rewind(); 

      IntBuffer buffBlend = IntBuffer.allocate(blend.getWidth() * blend.getHeight()); 
      blend.copyPixelsToBuffer(buffBlend); 
      buffBlend.rewind(); 

      IntBuffer buffOut = IntBuffer.allocate(base.getWidth() * base.getHeight()); 
      buffOut.rewind(); 

      while (buffOut.position() < buffOut.limit()) { 

       int filterInt = buffBlend.get(); 
       int srcInt = buffBase.get(); 

       int redValueFilter = Color.red(filterInt); 
       int greenValueFilter = Color.green(filterInt); 
       int blueValueFilter = Color.blue(filterInt); 

       int redValueSrc = Color.red(srcInt); 
       int greenValueSrc = Color.green(srcInt); 
       int blueValueSrc = Color.blue(srcInt); 

       int redValueFinal = colordodge(redValueFilter, redValueSrc); 
       int greenValueFinal = colordodge(greenValueFilter, greenValueSrc); 
       int blueValueFinal = colordodge(blueValueFilter, blueValueSrc); 


       int pixel = Color.argb(255, redValueFinal, greenValueFinal, blueValueFinal); 


       buffOut.put(pixel); 
      } 

      buffOut.rewind(); 

      base.copyPixelsFromBuffer(buffOut); 
      blend.recycle(); 

      return base; 
     } 
여기

색상을 얻을 효과에게 내가 원래의 스케치 이미지를 만들기 위해 노력하고

private int colordodge(int in1, int in2) { 
      float image = (float)in2; 
      float mask = (float)in1; 
      return ((int) ((image == 255) ? image:Math.min(255, (((long)mask << 8)/(255 - image))))); 
     } 

를 얻기 위해 픽셀에 대한 회피 방법을 수행한다 사진,이 방법을 사용하면 컬러 전체 형식으로 이미지를 만화화할 수 있지만 흑백 연필 스케치 형식이 필요합니다. 아이디어가 있다면 공유하십시오. 이 방법은 연필 스케치에이 코드를 넣어 당신

1

에 유용

희망, 나

public Bitmap Changetosketch(Bitmap bmp) { 
    Bitmap Copy, Invert, Result; 
    Copy = toGrayscale(bmp); 
    Invert = createInvertedBitmap(Copy); 
    Invert = Blur.blur(this, Invert); 
    Result = ColorDodgeBlend(Invert, Copy); 
    return Result; 
} 
public static Bitmap toGrayscale(Bitmap src) 
{ 
    final double GS_RED = 0.299; 
    final double GS_GREEN = 0.587; 
    final double GS_BLUE = 0.114; 

    // create output bitmap 
    Bitmap bmOut = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig()); 
    // pixel information 
    int A, R, G, B; 
    int pixel; 

    // get image size 
    int width = src.getWidth(); 
    int height = src.getHeight(); 

    // scan through every single pixel 
    for (int x = 0; x < width; ++x) { 
     for (int y = 0; y < height; ++y) { 
      // get one pixel color 
      pixel = src.getPixel(x, y); 
      // retrieve color of all channels 
      A = Color.alpha(pixel); 
      R = Color.red(pixel); 
      G = Color.green(pixel); 
      B = Color.blue(pixel); 
      // take conversion up to one single value 
      R = G = B = (int) (GS_RED * R + GS_GREEN * G + GS_BLUE * B); 
      // set new pixel color to output bitmap 
      bmOut.setPixel(x, y, Color.argb(A, R, G, B)); 
     } 
    } 

    // return final image 
    return bmOut; 
} 

public static Bitmap createInvertedBitmap(Bitmap src) { 
    Bitmap bmOut = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig()); 
    // color info 
    int A, R, G, B; 
    int pixelColor; 
    // image size 
    int height = src.getHeight(); 
    int width = src.getWidth(); 

    // scan through every pixel 
    for (int y = 0; y < height; y++) { 
     for (int x = 0; x < width; x++) { 
      // get one pixel 
      pixelColor = src.getPixel(x, y); 
      // saving alpha channel 
      A = Color.alpha(pixelColor); 
      // inverting byte for each R/G/B channel 
      R = 255 - Color.red(pixelColor); 
      G = 255 - Color.green(pixelColor); 
      B = 255 - Color.blue(pixelColor); 
      // set newly-inverted pixel to output image 
      bmOut.setPixel(x, y, Color.argb(A, R, G, B)); 
     } 
    } 
    return bmOut; 
} 
public Bitmap ColorDodgeBlend(Bitmap source, Bitmap layer) { 
    Bitmap base = source.copy(Bitmap.Config.ARGB_8888, true); 
    Bitmap blend = layer.copy(Bitmap.Config.ARGB_8888, false); 

    IntBuffer buffBase = IntBuffer.allocate(base.getWidth() * base.getHeight()); 
    base.copyPixelsToBuffer(buffBase); 
    buffBase.rewind(); 

    IntBuffer buffBlend = IntBuffer.allocate(blend.getWidth() * blend.getHeight()); 
    blend.copyPixelsToBuffer(buffBlend); 
    buffBlend.rewind(); 

    IntBuffer buffOut = IntBuffer.allocate(base.getWidth() * base.getHeight()); 
    buffOut.rewind(); 

    while (buffOut.position() < buffOut.limit()) { 

     int filterInt = buffBlend.get(); 
     int srcInt = buffBase.get(); 

     int redValueFilter = Color.red(filterInt); 
     int greenValueFilter = Color.green(filterInt); 
     int blueValueFilter = Color.blue(filterInt); 

     int redValueSrc = Color.red(srcInt); 
     int greenValueSrc = Color.green(srcInt); 
     int blueValueSrc = Color.blue(srcInt); 

     int redValueFinal = colordodge(redValueFilter, redValueSrc); 
     int greenValueFinal = colordodge(greenValueFilter, greenValueSrc); 
     int blueValueFinal = colordodge(blueValueFilter, blueValueSrc); 


     int pixel = Color.argb(255, redValueFinal, greenValueFinal, blueValueFinal); 


     buffOut.put(pixel); 
    } 

    buffOut.rewind(); 

    base.copyPixelsFromBuffer(buffOut); 
    blend.recycle(); 

    return base; 
} 

private int colordodge(int in1, int in2) { 
    float image = (float)in2; 
    float mask = (float)in1; 
    return ((int) ((image == 255) ? image:Math.min(255, (((long)mask << 8)/(255 - image))))); 
} 
이 작업
관련 문제