-2

在为图像箱提供的示例中,我有一个与分形示例(“6.2 生成分形”部分,https://github.com/PistonDevelopers/image )相关的问题

1)在线

image::ImageLuma8(imgbuf).save(fout, image::PNG).unwrap();

我收到以下编译错误消息(rustc 1.25.0):

error[E0061]: this function takes 1 parameter but 2 parameters were supplied
  --> src/main.rs:52:31
   |
52 |     image::ImageLuma8(imgbuf).save(fout, image::PNG).unwrap();
   |                               ^^^^ expected 1 parameter

感谢您的帮助!

2)另外注意我必须改变

use num_complex::Complex;

use num::complex::{Complex};

在示例的开头。也许 crate num_complex 不再存在?

4

1 回答 1

1

在 PistonDevelopers 的“6.2 Generate Fractals”一节中,无法成功编译原始示例。好像有一些过时的参数设置,这里是一个更新的版本。希望这有帮助。

//! An example of generating julia fractals.
extern crate image;
extern crate num;

use self::num::Complex;
use std::path::Path;

fn main() {
    let max_iterations = 256u16;

    let imgx = 800;
    let imgy = 800;

    let scalex = 4.0 / imgx as f32;
    let scaley = 4.0 / imgy as f32;

    // let mut y = 0;
    // Create a new ImgBuf with width: imgx and height: imgy
    let mut imgbuf: image::GrayImage = image::ImageBuffer::new(imgx, imgy);

    // Iterate over the coordinates and pixels of the image
    for (x, y, pixel) in imgbuf.enumerate_pixels_mut() {
        let cy = y as f32 * scaley - 2.0;
        let cx = x as f32 * scalex - 2.0;

        let mut z = Complex::new(cx, cy);
        let c = Complex::new(-0.4, 0.6);

        let mut i = 0;

        for t in 0..max_iterations {
            if z.norm() > 2.0 {
                break;
            }
            z = z * z + c;
            i = t;
        }

        // Create an 8bit pixel of type Luma and value i
        // and assign in to the pixel at position (x, y)
        *pixel = image::Luma([i as u8]);
    }

    // Save the image as “fractal.png”
    let path = Path::new("fractal.png");

    // We must indicate the image's color type and what format to save as
    image::ImageLuma8(imgbuf).save(path).unwrap();
}
于 2018-05-20T10:07:37.617 回答