Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I zoom an image using nearest-neightbor scaling? #1238

Closed
alexispurslane opened this issue Aug 21, 2018 · 2 comments
Closed

How do I zoom an image using nearest-neightbor scaling? #1238

alexispurslane opened this issue Aug 21, 2018 · 2 comments

Comments

@alexispurslane
Copy link

I'm trying to use Piston to make a 2D pixel-art game, and as part of that I need to zoom the textures by 2x. Unfortunately, when I scale the images, Piston uses a standard, blurry, scaling algorithm. What I need is a simpler, sharper scaling algorithm, such as NN. Here's my code:

    let transform = c
        .transform
        .trans(x as f64, y as f64)
        .zoom(2.0);
    image(tile, transform, gl);

Here's what my scaled image looks like (just one tile):

image

@omicronns
Copy link

omicronns commented Nov 7, 2018

You can set scaling method when creating texture:

let tex = Texture::from_path(
    factory,
    "tex.png",
    Flip::None,
    &TextureSettings::new().mag(texture::Filter::Nearest)
).unwrap();

@bvssvni
Copy link
Member

bvssvni commented May 21, 2024

Closing.

@bvssvni bvssvni closed this as completed May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants