Code Monkey home page Code Monkey logo

Comments (3)

Cykooz avatar Cykooz commented on May 26, 2024

I have been trying to do a crop of a 640x480 image to a 640x640 image

You can't crop into size bigger than size of source image.
If you want to store resizing result into some region of destination image, you must:

  • create a big destination image (640x640);
  • get DynamicImageViewMut from it;
  • crop this view into smaller (640x480) DynamicImageViewMut;
  • use cropped DynamicImageViewMut as dst_image parameter for Resizer::resize() function.

from fast_image_resize.

seddonm1 avatar seddonm1 commented on May 26, 2024

Hi @Cykooz .

Sorry I was not very clear in my initial message. Here is some code to reproduce the issue:

use fast_image_resize::{CropBox, Image, PixelType, ResizeAlg, Resizer};
use std::num::NonZeroU32;

fn main() {
    let source_image = Image::new(
        NonZeroU32::new(640).unwrap(),
        NonZeroU32::new(480).unwrap(),
        PixelType::U8x3,
    );

    // Create container for data of destination image. Initialised as RGB (0,0,0)
    let mut target_image = Image::new(
        NonZeroU32::new(640).unwrap(),
        NonZeroU32::new(640).unwrap(),
        PixelType::U8x3,
    );

    // Get mutable view of destination image data
    let mut dst_view = target_image
        .view_mut()
        .crop(CropBox {
            left: 0,
            top: 80,
            width: NonZeroU32::new(640).unwrap(),
            height: NonZeroU32::new(480).unwrap(),
        })
        .unwrap();

    // do the resize
    Resizer::new(ResizeAlg::Nearest)
        .resize(&source_image.view(), &mut dst_view)
        .unwrap();
}

from fast_image_resize.

Cykooz avatar Cykooz commented on May 26, 2024

Oh, you are right. It is a bug.
I've fixed error in version 2.7.3.
Thank you.

from fast_image_resize.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.