0 Replies Latest reply on Oct 7, 2010 12:54 PM by M_Biff

    Help with bitmapdata and sephiroth

    M_Biff

      I bought some out of the box product deisgn software (design your own t-shirt kinda thing) and I'm having trouble getting it output transparent PNGs. The company/person who wrote the software has been unresponsive.  It was meant to create pdfs or jpegs but I need a clean transparent PNG.  What I've got now is a PNG that is mostly transparent but the edges of user added images/text have a white noise around the border. 313_front_test.png

      I've put the image on a blue background just to demonstrate the problem.

       

      The program uses the sephiroth printscreen function to generate the image but this function was meant to generate jpegs and by default just makes all white transparent (I need user added white to show as white).  Here is the version of code we're using now:

      class it.sephiroth.PrintScreen {

       

          public var addListener:Function
          public var broadcastMessage:Function

       

          private var id:   Number;
          public  var record:LoadVars;

       

          function PrintScreen(){
              AsBroadcaster.initialize( this );
          }

       

          public function print(mc:MovieClip, x:Number, y:Number, w:Number, h:Number){
              broadcastMessage("onStart", mc);
              if(x == undefined) x = 0;
              if(y == undefined) y = 0;
              if(w == undefined) w = mc._width;
              if(h == undefined) h = mc._height;
              var bmp:BitmapData = new BitmapData(w, h, true);
              record = new LoadVars();
              record.width  = w
              record.height = h
              record.cols   = 0
              record.rows   = 0
              var matrix = new Matrix();
              matrix.translate(-x, -y)
              bmp.draw(mc, matrix, new ColorTransform(), 1, new Rectangle(0, 0, w, h));
              id = setInterval(copysource, 5, this, mc, bmp);
          }

       

          private function copysource(scope, movie, bit){
              var pixel:Number
              var str_pixel:String
              scope.record["px" + scope.record.rows] = new Array();
              for(var a = 0; a < bit.width; a++){
                  pixel     = bit.getPixel(a, scope.record.rows)
                  str_pixel = pixel.toString(16)
                  if(pixel == 0xFFFFFF) str_pixel = "";   // don't send blank pixel
                  scope.record["px" + scope.record.rows].push(str_pixel)
              }
              scope.broadcastMessage("onProgress", movie, scope.record.rows, bit.height)  // send back the progress status
              scope.record.rows += 1
              if(scope.record.rows >= bit.height){
                  clearInterval(scope.id)
                  scope.broadcastMessage("onComplete", movie, scope.record)   // completed!
                  bit.dispose();
              }
          }
      }

       

      the php we're using instead of the original sephiroth code is:

      $w = (int)$_REQUEST['width'];

       

      $h = (int)$_REQUEST['height'];

       

      $path=$_REQUEST['path'];

       

      $img = imagecreatetruecolor($w, $h);

       

       

       

      imageSaveAlpha($img, true);

       

      imageAlphaBlending($img, false);

       

      $transparent = imageColorAllocateAlpha($img, 0, 0, 0, 127);

       

      imagefilledrectangle($img, 0, 0, $w-1, $h-1, $transparent);

       

      imageAlphaBlending($img, true);

       

      $rows = 0;
      $cols = 0;

       

      for($rows = 0; $rows < $h; $rows++){
         
          $c_row = explode(",", $_POST['px' . $rows]);
          for($cols = 0; $cols < $w; $cols++){
             
              $value = $c_row[$cols];
             
              if($value != ""){

       

                  $hex = $value;
                  while(strlen($hex) < 6){$hex = "0" . $hex;}
                  $r = hexdec(substr($hex, 0, 2));
                  $g = hexdec(substr($hex, 2, 2));
                  $b = hexdec(substr($hex, 4, 2));
                  $test = imagecolorallocate($img, $r, $g, $b);
                  imagesetpixel($img, $cols, $rows, $test);
                 
                 
              }
          }
      }

       

       

             

       

      $path=dirname(dirname(dirname(__FILE__))).'/orders/'.$path.".png";
      imagepng($img,$path);
      echo "&dta=OK&";

       

       

      Any help would be great apreciated, I'm only somewhat familiar with flash and I've hit a dead end.  Let me know if you need more information.