Page 1 of 1
Resizing ImageData
Posted: Mon Nov 09, 2015 4:28 pm
by Dr.Tyler O.
I've been looking everywhere and haven't found any information regarding it. I'm looking to resize imagedata and then encode it, not draw it on the screen. Can Love2D accomplish this?
Re: Resizing ImageData
Posted: Mon Nov 09, 2015 4:52 pm
by arampl
You can create new empty ImageData with needed w&h, then use "paste" method from source ImageData.
If you want to scale source image to new size then create canvas with needed w&h, scale and draw image to it, then get ImageData from it.
Re: Resizing ImageData
Posted: Mon Nov 09, 2015 5:27 pm
by zorg
Or, if you want to forego doing anything with the gpu pipeline, then you can also write a function that accepts an imagedata, and two numbers representing the output dimensions (and maybe another for the scaling function, or just hardcode one), and you can calculate the resulting pixels using any number of scaling algorithms that exist already. Nearest neighbor would be probably the simplest.
Re: Resizing ImageData
Posted: Mon Nov 09, 2015 8:53 pm
by Evine
Needed something similar myself so I wrote it now
Now the down-sampling is rather poor. But it works.
Code: Select all
local function createThumbnail(fileName,scale)
scale = scale or 1
local img = love.graphics.newImage(fileName)
local canvas = love.graphics.newCanvas(img:getWidth()*scale , img:getHeight()*scale)
love.graphics.push("all")
local wasCanvas = love.graphics.getCanvas()
love.graphics.setCanvas(canvas)
canvas:clear()
love.graphics.draw(img,0,0,0,scale)
love.graphics.pop()
love.graphics.setCanvas(wasCanvas)
local imageData = canvas:getImageData()
return imageData
end