## Help With Images

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
SmellyFishstiks
Prole
Posts: 4
Joined: Mon Jun 01, 2020 10:37 am

### Help With Images

Hi! I'm kinda new to Löve2d and I wanted some help with figuring out how to create .pngs.

I have this code:

screenshotnum=0
function screenshoter(key)

if input.isDown(key) then

screenshotnum = screenshotnum + 1
local filename = love.window.getTitle().." "..screenshotnum..".png"

image = love.image.newImageData(graph.getWidth(),graph.getHeight())
filedata = image:encode("png", filename)
filedata = love.filesystem.newFile(filename)
end

end

and it does save files, But even though
the size of the images are correct it doesn't save the iamge data to the new png.
like all of the pixels are just pure alpha.

can someone help thanks.

zorg
Party member
Posts: 2942
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

### Re: Help With Images

you are just creating an empty ImageData object the size of graph, whatever that is.
if you want to get the contents of the screen, you need to use love.graphics.captureScreenshot since that returns an ImageData of the screen contents... kinda.
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.

SmellyFishstiks
Prole
Posts: 4
Joined: Mon Jun 01, 2020 10:37 am

### Re: Help With Images

Thanks for telling me but I figured that out yesterday.. I wasen't sure if the fourm post was verified yet though to comment that. I was wondering though how would I use this for shaders? like if I test the pixel color at a given pixel how can I use capturescreenshot to do that? But the images that capturescreenshot puts out are upscaled x12. : < I wish that was a var you could set the size.. anyways thanks for commenting! I figured out that's what I was doing and felt silly I'm pretty new to Love and this is my first time using the fourms.

zorg
Party member
Posts: 2942
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

### Re: Help With Images

Well, with today's GPU architectures, what you want to do is highly inefficient, not to mention that the function i linked is not exactly "frame-accurate", in that it might capture a frame different from what you'd be expecting to.

Usually, you'd want to do all pixel-like manipulations on the CPU side instead... and that tends to have its own limits as well.
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.

SmellyFishstiks
Prole
Posts: 4
Joined: Mon Jun 01, 2020 10:37 am

### Re: Help With Images

ok; I'll see if I want to atempt it later then. I came from PICO-8 and in pico there's a built-in way to test the screen and super easy useing Pget and Pset. IDK thanks for anwsering!

Sasha264
Citizen
Posts: 71
Joined: Mon Sep 08, 2014 7:57 am

### Re: Help With Images

@SmellyFishstiks, welcome!

In love Image & Canvas is stored in video (gpu) memory and ImageData is stored in cpu memory.
And here is some methods to copy from one to another.
To copy gpu -> cpu here is this function https://love2d.org/wiki/Canvas:newImageData

I used it a lot in my projects. Because there is no another way to do some sort of things.
Yes, it is inefficient because of hardware architecture (as some people keep telling me), but it is not that bad inefficient.
In my experience I still can achieve 240+ fps, even if I copy small canvas every frame to cpu memory.
And if game runs on device with integrated gpu, then the word 'inefficient' can be skipped at all =)

SmellyFishstiks
Prole
Posts: 4
Joined: Mon Jun 01, 2020 10:37 am

### Re: Help With Images

Ok thanks for letting me know! I'm going to come back to this later because this is going to be useful!

My window size is like this:

Code: Select all

version=0.6
versiondate="6/17/2020"
function love.conf(t)
t.window.title = "Capsule Critters v"..version
t.window.width =  12*16*6
t.window.height = 7*16*6
t.window.highdpi = true
t.window.x =290/2
t.window.y = 0

t.window.minwidth = 12*16*6
t.window.minheight = 7*16*6
t.window.resizable = false

t.identity = "capsulecritters"

t.window.icon = "icon.png"
end

So hopefully that's not to big for love to handle. if I scale size somthing by like 6 for my case, do I only have to test and set the pixels every 6 pixels to achive the same effect? because that way it would cut down on the cost a lot. (I love.graphics.scale() by 6 usally.)
(12 & 7 are number of cells, 16 is the size of each cell, 6 is the default and usally used scalesize to make the window perfectly lined up.)

### Who is online

Users browsing this forum: Google [Bot] and 22 guests