Neko loading images with haxe.Http and writing

112 views
Skip to first unread message

[mck]

unread,
Nov 19, 2014, 11:55:51 AM11/19/14
to haxe...@googlegroups.com
Hi all,

I am currently working on a project with a lot of images.
To start prototyping the app I wanted to create dummy-data (json and images).
But because the use of a lot of images, these images should but unique.

I used the neko target, and created the json file with ease.
But its impossible to generate images from scratch with text using neko.
(I have the size and color of the images under controle!)

So for the I thought it would be useful to use
http://dummyimage.com/600x400/000/fff.png&text=test
so I can generate different sizes, color and text

This is part of the code I use.
(I need to put some delays in there, because I want to play nice with dummyimage.com)


        // load image
        var req = new haxe.Http('http://dummyimage.com/600x400/000/fff.png&text=test');
        req.onData = function (pdata){
            trace('first 100 bytes: '+pdata.substr(0, 100));
            writeStringToPng(pdata);            
        }
        req.onError = function (error){
            trace('error: $error');
        }
        req.request(true);


function writeStringToPng (str:String):Void
{
        var bytes:Bytes = Bytes.ofString(str);
        var data = format.png.Tools.buildRGB (660,400,bytes);
        var out = sys.io.File.write('bin/boo.png',true);
        new format.png.Writer(out).write(data);    
}


This code fails when I try to convert the bytes to data.


Perhaps my code is related to this issue:
https://github.com/HaxeFoundation/haxe/issues/2586

Any idea how to fix this?


Thx

Cambiata

unread,
Nov 19, 2014, 2:12:26 PM11/19/14
to haxe...@googlegroups.com
Hi!

A workaround could be to include NME in your solution.
(NME can be used "headless" in a command line app, without any use of graphic interface.)
This will give you access to the URLLoader wich can be used in binary mode - this should solve the haxe.Http string issues.

Jonas

[mck]

unread,
Nov 19, 2014, 4:42:47 PM11/19/14
to haxe...@googlegroups.com
Hi Jonas,

It sounded as a good tip, but I can't get it to work
I keep on getting this message:

/usr/lib/haxe/lib/nme/5,1,8/nme/events/HTTPStatusEvent.hx:4: characters 7-33 : You cannot access the flash package while targeting neko (for flash.net.URLRequestHeader)

I guess I will rewrite it in openfl.

Unless someone has another idea!

Cambiata

unread,
Nov 19, 2014, 6:22:16 PM11/19/14
to haxe...@googlegroups.com
Ah, recognize that one.
You could try with
> haxelib install nme 4.0.2
and then
> haxelib set nme 4.0.2
It should work.

J

[mck]

unread,
Nov 26, 2014, 7:17:08 AM11/26/14
to haxe...@googlegroups.com
Hi Jonas,

I eventually used openfl for it.
then I just generate my own images

later I tried to port the same code I used in openfl project to my first neko project and changed package to NME
but that failed ... and because I had a working version I stopped trying...

thx for you help
Reply all
Reply to author
Forward
0 new messages