dcsimg
A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Another 'save as image' thread..

  1. #1
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755

    Another 'save as image' thread..

    ok.. so I finally wanted to actually try instead of just reading it.. (ie: had a need for it)


    I read the same basic threads/posts that go to the same tuts.. however I couldnt get things to work..

    not sure if AS, PHP..or if a hosting problem possibly? (permissions)

    long story short.. I am trying to get the most straight forward (no filters..no video capture..etc) method to work.

    just a clip on stage.. has some scribbles or other movieClip attached inside fo it.. but whatever is inside tis 'containerClip' should be copied 7 sent to a php script to be made into an image..



    AS:
    PHP Code:
    import flash.display.BitmapData;

    button1.onPress = function(){
        
    output();
    }

    function 
    output() {
        var 
    snap:BitmapData = new BitmapData(containerClip._widthcontainerClip._heightfalse0xFFFFFF);
        
    snap.draw(containerClip);
        var 
    pixels:Array = new Array();
        var 
    w:Number snap.width;
        var 
    h:Number snap.height;
        for (var 
    0a<=wa++) {
            for (var 
    0b<=hb++) {
                var 
    tmp snap.getPixel(ab).toString(16);
                
    pixels.push(tmp);
            }
        }
        
        
    //send to php for image creation
        
    var output:LoadVars = new LoadVars();
        
    output.img pixels.toString();
        
    output.height h;
        
    output.width w;
        
    output.send("http://www.domainname.com/folder/show.php""output""POST");



    PHP:
    PHP Code:
    <?php
        $data 
    explode(","$_POST['img']);
        
    $width $_POST['width'];
        
    $height $_POST['height'];
        
    $image=imagecreatetruecolor$width ,$height );
        
    $background imagecolorallocate$image ,);
        
    //Copy pixels
        
    $i 0;
        for(
    $x=0$x<=$width$x++){
            for(
    $y=0$y<=$height$y++){
                
    $int hexdec($data[$i++]);
                
    $color ImageColorAllocate ($image0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF $int);
                
    imagesetpixel $image $x $y $color );
            }
        }
        
    //Output image and clean
        
    header"Content-type: image/jpeg" );
        
    ImageJPEG$image );
        
    imagedestroy$image );    
    ?>
    I see it looks to be currently set-up for.jpg output.. I would eventually want it to be a .gif or .png.. so does that mean in the AS using getPixe32() instead? or is there other changes?

    Thanks


    sorry this is AS2.0 only (Flash 8)

    this link:
    http://www.quasimondo.com/archives/000572.php

    source files are sorta working out of the box.. as I see the image being created.. however he is using a custom class with the file upload reference included..and Id like to have something just VERY simple and then move forward..

    on click on button..take pre-determined containerClip (and all nested content).. send the data to php script on server,.. php script takes bitmap data/array creates a .png (or whatever at this point).. and then returns some message back to flash.. saying all is complete.. and maybe a url?

    at this point.. thing will change.. but Id like to get here if anyone can help or offer suggestions? ultimately I guess id like for it to be emailed..

    or just have it open in a new page?..

    thanks

  2. #2

  3. #3
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    have you tried using the sepiroth class?

    http://www.sephiroth.it/tutorials/fl...en/page002.php
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  4. #4
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    have you tried using the sepiroth class?

    http://www.sephiroth.it/tutorials/fl...en/page002.php
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  5. #5
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    Yeah I looked at that..thanks.. and I was looking for some help on DUMBING it down..

    would like to NOT have it be an external class for first use with it..
    also wanted to try and trim outt he PRINT stuff..etc..

    just a basic bitMap copy/draw.. and pass the bitMap pixel data to a php script..

    I want to break it down into 'steps'.. so I wcan work through it and add as I understand more.. like adding the file reference stuff, upload feedback..etc

    Thanks

  6. #6
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    Hey Zain-

    not sure if you're around..

    anywho.. just getting back around to this...


    so if anyone can help..please do.

    try to break it down in simple steps and then build off it.. (NOT using anyone's external classes)

    so keeping with the initial sample code:
    PHP Code:
    import flash.display.BitmapData;

    button1.onPress = function(){
        
    output();
    }

    function 
    output() {
        var 
    snap:BitmapData = new BitmapData(containerClip._widthcontainerClip._heightfalse0xFFFFFF);
        
    snap.draw(containerClip);
        var 
    pixels:Array = new Array();
        var 
    w:Number snap.width;
        var 
    h:Number snap.height;
        for (var 
    0a<=wa++) {
            for (var 
    0b<=hb++) {
                var 
    tmp snap.getPixel(ab).toString(16);
                
    pixels.push(tmp);
            }
        }
        
        
    //send to php for image creation
        
    var output:LoadVars = new LoadVars();
        
    output.img pixels.toString();
        
    output.height h;
        
    output.width w;
        
    output.send("http://www.domainname.com/folder/show.php""_blank""POST");


    seems fairly straight forward..

    a function that makes a copy/snap shot of the pixel data in a specific clip (ie: 'containerClip' in this scenario)

    I pass this bitMap data to the php script..that should just create an image in the same directory of the php script.. (or so this is my goal)


    I know next to zero PHP.. so maybe the problem lies there?

    PHP Code:
    <?php
        $data 
    explode(","$_POST['img']);
        
    $width $_POST['width'];
        
    $height $_POST['height'];
        
    $image=imagecreatetruecolor$width ,$height );
        
    $background imagecolorallocate$image ,);
        
    //Copy pixels
        
    $i 0;
        for(
    $x=0$x<=$width$x++){
            for(
    $y=0$y<=$height$y++){
                
    $int hexdec($data[$i++]);
                
    $color ImageColorAllocate ($image0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF $int);
                
    imagesetpixel $image $x $y $color );
            }
        }
        
    //Output image and clean
        
    header"Content-type: image/jpeg" );
        
    ImageJPEG$image );
        
    imagedestroy$image );    
    ?>
    when I test.. I get a huge HANG (testing through IDE).. like its trying to pass a bunch of data or something.. it finally becomes responsive again, however.. there is never any image created??

    I dont believe this to be a permission fo host problem.. as testing the default (after I scribble a little in the focus clip to be exported) from:

    http://www.quasimondo.com

    DOES in fact create an image.. there are some other errors as well.. this has a saving percentage too I believe (or maybe an UPLOAD percentage form using a FileReference() instance?)

    anyways.. any help is appreciated thanks

  7. #7
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    latest attempt cleaned up some:

    PHP Code:
    import flash.display.BitmapData;

    button1.onPress = function(){
        
    trace("WIDTH CHECK 1 : "+containerClip._width);
        
    savePic(containerClip);
        
    }


    function 
    savePic(mc:MovieClip) {
        var 
    snapShot:BitmapData = new BitmapData(mc._widthmc._heightfalse0xFFFFFF);
        
    trace("WIDTH CHECK 3 : "+mc._width);
        
    snapShot.draw(containerClip);
        var 
    pixels:Array = new Array();
        var 
    w:Number snapShot.width;
        var 
    h:Number snapShot.height;
        for (var 
    0a<=wa++) {
            for (var 
    0b<=hb++) {
                var 
    tmp snapShot.getPixel(ab).toString(16);
                
    pixels.push(tmp);
            }
        }
        
        
    //send to php for image creation
        
    var output:LoadVars = new LoadVars();
        
    /*
        output.onLoad = function(success){
            if(!success){
                trace("PHP NOT FOUND");
            }else{
                trace("PHP SCRIPT FOUND");
            }
        }
        */
        
    output.img pixels.toString();
        
    output.height h;
        
    output.width w;
        
    output.send("http://www.dmstudios.net/demos/makepic/makePic2.php""_blank""POST");


    If someone could tell me if its a AS side or PHP side problem..even that would help me to narrow down my search..

    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center