문제

나는 이미지를 가져 오는 Actionscript와 함께 Flex 3 응용 프로그램에 무언가를 쓰려고 노력하고 있으며 사용자가 버튼을 클릭하면 모든 흰색 (ISH) 픽셀을 제거하고 투명하게 변환합니다. 나는 정확히 흰색을 시도했지만 가장자리 주위에 많은 아티팩트를 얻습니다. 다음 코드를 사용하여 다소 가까워졌습니다.

targetBitmapData.threshold(sourceBitmapData, sourceBitmapData.rect, new Point(0,0), ">=", 0xFFf7f0f2, 0x00FFFFFF, 0xFFFFFFFF, true);

그러나 빨간색 또는 노란색이 사라집니다. 왜 이것을하고 있습니까? 이 작업을 수행하는 방법을 정확히 잘 모르겠습니다. 내 필요에 더 적합한 또 다른 기능이 있습니까?

도움이 되었습니까?

해결책

친구와 나는 프로젝트를 위해 시간을 거슬러 올라가려고 노력했고, Actionscript 에서이 작업을 수행하는 인라인 방법을 작성하는 것이 엄청나게 느리다는 것을 알았습니다. 각 픽셀을 스캔하고 계산을 수행해야하지만 Pixelbender로 수행하는 것은 번개가 빠른 것으로 판명되었습니다 (Flash 10을 사용할 수있는 경우, 그렇지 않으면 느리게 붙어 있습니다).

픽셀 벤더 코드는 다음과 같습니다.

input image4 src;
output float4 dst;

// How close of a match you want
parameter float threshold
<
  minValue:     0.0;
  maxValue:     1.0;
  defaultValue: 0.4;
>;

// Color you are matching against.
parameter float3 color
<
  defaultValue: float3(1.0, 1.0, 1.0);
>;

void evaluatePixel()
{
  float4 current = sampleNearest(src, outCoord());
  dst = float4((distance(current.rgb, color) < threshold) ? 0.0 : current);
}

다음과 같은 것을 사용할 수 있으므로 수행 해야하는 경우 다음과 같은 것을 사용할 수 있습니다.

function threshold(source:BitmapData, dest:BitmapData, color:uint, threshold:Number) {
  dest.lock();

  var x:uint, y:uint;
  for (y = 0; y < source.height; y++) {
    for (x = 0; x < source.width; x++) {
      var c1:uint = source.getPixel(x, y);
      var c2:uint = color;
      var rx:uint = Math.abs(((c1 & 0xff0000) >> 16) - ((c2 & 0xff0000) >> 16));
      var gx:uint = Math.abs(((c1 & 0xff00) >> 8) - ((c2 & 0xff00) >> 8));
      var bx:uint = Math.abs((c1 & 0xff) - (c2 & 0xff));

      var dist = Math.sqrt(rx*rx + gx*gx + bx*bx);

      if (dist <= threshold)
        dest.setPixel(x, y, 0x00ffffff);
      else
        dest.setPixel(x, y, c1);
    }
  }
  dest.unlock();
}

다른 팁

당신은 실제로 그것을 할 수 있습니다 없이 내장 덕분에 픽셀 벤더와 실시간 임계 값 기능 :

// Creates a new transparent BitmapData (in case the source is opaque)
var dest:BitmapData = new BitmapData(source.width,source.height,true,0x00000000);

// Copies the source pixels onto it
dest.draw(source);

// Replaces all the pixels greater than 0xf1f1f1 by transparent pixels
dest.threshold(source, source.rect, new Point(), ">", 0xfff1f1f1,0x00000000);

// And here you go ...  
addChild(new Bitmap(dest));     

위의 코드가 다양한 색상을 투명하게 만드는 것처럼 보입니다.

의사 코드 :
TargetBitMapData의 각 픽셀에 대해
픽셀의 색상이> = #fff7f0f2 인 경우
색상을 #00ffffff로 변경하십시오

이와 같은 것이 완벽하지 않을 것입니다. 밝은 색상을 잃을 것이기 때문에 어떤 색상이 변경 될지 정확히 볼 수있는 온라인 색상 선택기를 찾을 수 있습니다.

픽셀 벤더 코드 1의 답변 :

dst = float4 ((거리 (current.rgb, color) <Threshold)? 0.0 : 전류);

해야한다:

dst = (거리 (current.rgb, color) <임계 값)? float4 (0.0) : 전류;

또는

if (거리 (current.rgb, color) <Threshold) dst = float4 (0.0); else dst = float4 (현재);

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top