Resizing ImageData
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Dr.Tyler O.
- Citizen
- Posts: 58
- Joined: Tue Jul 29, 2014 9:17 am
- Location: United States
Resizing ImageData
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?
Any topic I have ever posted that I felt did not require a .love file, although they were requested, never required one so I would appreciate if you did not ask me to supply one unless you think that I am ignorant for not doing so.
Re: Resizing ImageData
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.
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.
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Resizing ImageData
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.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: Resizing ImageData
Needed something similar myself so I wrote it now
Now the down-sampling is rather poor. But it works.
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
Artal, A .PSD loader: https://github.com/EvineDev/Artal
Who is online
Users browsing this forum: Bing [Bot] and 6 guests