private FREObject RunArrayTests(FREContext ctx, uint argc, FREObject[] argv) { Trace("***********Start Array test***********"); if (argc < 4) { return(new FreException("Not enough args").RawValue); } var inFre0 = new FREArray(argv[0]); var inFre1 = new FREArray(argv[1]); var inFre2 = new FREArray(argv[2]); var inFre3 = new FREArray(argv[3]); var airArray = inFre0.ToArrayList(); var airArrayLen = inFre0.Length; inFre0[1] = 123.ToFREObject(); foreach (var fre in inFre0) { Trace("iterate over FREArray", fre.AsInt()); } var airVectorString = inFre1.AsStringArray(); var airVectorNumber = inFre2.AsDoubleArray(); var airVectorBoolean = inFre3.AsBoolArray(); Trace("Array passed from AIR:", string.Join(",", airArray.ToArray())); Trace("AIR Array length:", airArrayLen); Trace("Vector.<String> passed from AIR:", string.Join(",", airVectorString.ToArray())); Trace("Vector.<Number> passed from AIR:", string.Join(",", airVectorNumber.ToArray())); Trace("Vector.<Boolean> passed from AIR:", string.Join(",", airVectorBoolean.ToArray())); var newFreArray = new FREArray("Object", 5, true); Trace("New Array of Objects should be 5?", newFreArray.Length); var itemZero = inFre0[0]; var itemZeroVal = itemZero.AsInt(); Trace("AIR Array item 0 before change:", itemZeroVal); inFre0.Set(0, 56); var marks = new[] { 99, 98, 92, 97, 95 }; return(marks.ToFREObject()); }
public FREObject ResizeImage(FREContext ctx, uint argc, FREObject[] argv) { // Read from file try { var newW = Convert.ToInt32(new FreObjectSharp(argv[1]).Value); var newH = Convert.ToInt32(new FreObjectSharp(argv[2]).Value); var array = new FREArray(new FreObjectSharp(argv[0]).RawValue); var list = array.ToArrayList(); using (MagickImageCollection collection = new MagickImageCollection()) { string outputDir = ""; int i = 0; foreach (String inputPath in list) { FileInfo input = new FileInfo(inputPath); outputDir = input.Directory.CreateSubdirectory("small").FullName; FileInfo output = new FileInfo(outputDir + @"\" + input.Name); try { using (MagickImage image = new MagickImage(input)) { MagickGeometry size = new MagickGeometry(newW, newH); //image.Resize(size); genera un ciclo infinito en v84 image.AdaptiveResize(size); // Save the result image.Write(output.FullName); collection.Add(output.FullName); collection[i].AnimationDelay = 200; } } // Catch any MagickException catch (MagickException exception) { // Write excepion raised when reading the invalid jpg to the console Trace("ERROR: " + exception); return(new FreException(exception).RawValue); } i++; } // Optionally reduce colors QuantizeSettings settings = new QuantizeSettings(); settings.Colors = 256; collection.Quantize(settings); // Optionally optimize the images (images should have the same size). collection.Optimize(); // Save gif collection.Write(outputDir + @"\output.gif"); return(new FreObjectSharp(outputDir + @"\output.gif").RawValue); } } catch (Exception e) { Trace("Exception " + e); } return(FREObject.Zero); }