Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   ActionScript 1.0/2.0 (http://www.flasher.ru/forum/forumdisplay.php?f=93)
-   -   Save to jpeg (http://www.flasher.ru/forum/showthread.php?t=119220)

kiraml 15.12.2008 14:10

Save to jpeg
 
Здравствуйте, есть такая проблема, подскажите пожалуйста как её решить
Мне нужно сохранить картинку из свф в файл.
Код AS1/AS2:

import flash.display.BitmapData;
import flash.geom.Matrix;
 
_root.menu = new ContextMenu();
var context_menu:ContextMenu = new ContextMenu();
context_menu.customItems.push(new ContextMenuItem("Сохранить изображение", this.onContextMenu));
_root.menu = context_menu;
 
function onContextMenu() {
        trace("1");
        makeShadow();
}
 
function makeShadow() {
        trace("2");       
        capture(0);
}
 
/*
create a function that takes a snapshot of the Video object whenever it is called
and shows in different clips
*/

function capture(nr) {
        this["snapshot"+nr] = new BitmapData(_root._width, _root._height);
 
        this["snapshot"+nr].draw(_root,new Matrix());
        var t:MovieClip = createEmptyMovieClip("bitmap_mc"+nr, nr);
 
        //display the specified bitmap object inside the movie clip
        t.attachBitmap(this["snapshot"+nr],1);
        output(nr);
        //attachMovie("print_but", "bot"+nr, 100+nr, {_x:t._x+t._width+50, _y:t._y+t._height/2})
}
//Create a new bitmapdata, resize it 50 %, pass image data to a server script
// using a LoadVars object (large packet)
function output(nr) {
        //Here we will copy pixels data
        var pixels:Array = new Array();
        //Create a new BitmapData
        var snap = new BitmapData(this["snapshot"+nr].width, this["snapshot"+nr].height);
        //Matrix to scale the new image
        myMatrix = new Matrix();
        myMatrix.scale(1,1);
        //Copy image
        snap.draw(this["snapshot"+nr],myMatrix);
 
        var w:Number = snap.width, tmp;
        var h:Number = snap.height;
        //Build pixels array
        for (var a = 250; a<=w-150; a++) {
                for (var b = 0; b<=h-150; b++) {
                        tmp = snap.getPixel32(a, b).toString(16);
                        pixels.push(tmp.substr(1));
                }
        }
        //Create the LoadVars object and pass data to PHP script
        var output:LoadVars = new LoadVars();
        output.img = pixels.toString();
        output.height = h-150;
        output.width = w-400;
        //The page (and this movie itself) should be in a server to work
        output.send("show.php","output","POST");
        _root["bitmap_mc"+nr].removeMovieClip();
}
stop();

Тоесть я мувик рута копирую в битмап, а потом когда кидаю данные в пхп то отмечаю тот отрезок который именно мне нужен(собственно диаграмма)
http://www.realty4sale.ru/i1/diagram/2.html
только вот на серваке при обращении к show.php
Цитата:

Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 1048576 bytes) in /home/realty4s/public_html/i1/diagram/show.php on line 5
Я то вижу переполнение памяти, но как это исправить?
сам файл http://www.realty4sale.ru/i1/diagram/show.txt
на localhost работает все,
только имеет такой глюк, изображение какое то нечеткое http://www.realty4sale.ru/i1/diagram/diagram.JPG
Заранее спасибо.

chingachgoog 15.12.2008 15:02

1) Для освобождения памяти люди пишут аналог зипа и передают на сервер уже заархивированный массив точек.
2) getPixel32 просто так цвет точки не отдаст - даже в хелпе пример дается - надо побитовым смещением просчитывать. Можно еще попробывать также сделать сглаживание в методе draw().

mixery 15.12.2008 17:32

мб так?
http://www.flasher.ru/forum/showpost...3&postcount=13

kiraml 15.12.2008 18:10

да, спасибо mixery качество теперь отличное, но проблема беспокоит все же таки та же самая, идет загрузка на серваке пхп скрипта, и выдает ошибку ту же.
(контекстное меню-> сохранить изображение).
http://www.realty4sale.ru/i1/diagram/2.html

Цитата:

Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 71 bytes) in /home/realty4s/public_html/i1/diagram/show.php on line 2
вторая строка
PHP код:

$data explode(","$_POST['img']); 



Часовой пояс GMT +4, время: 02:14.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.