This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Ghifari160's profile picture

paintutils.drawImage not working

Started by Ghifari160, 15 March 2014 - 08:21 PM
Ghifari160 #1
Posted 15 March 2014 - 09:21 PM
For some reason, paintutils.drawImage is not working for me. I already put the right path but it still returning error.


local version = "1.0"
local url = "" --Update URL
img = paintutils.loadImage("/background.nfp") -- Background Image

--function init()

--end

paintutils.drawImage(img, 1, 1)
CometWolf #2
Posted 15 March 2014 - 10:53 PM
I swear, there's one of these every day lol. Your image does not exist, or is an invalid format.
oeed #3
Posted 16 March 2014 - 12:02 AM
What's the error?
theoriginalbit #4
Posted 16 March 2014 - 02:11 AM
I swear, there's one of these every day lol.
I can't wait for CC 1.6 and a large amount of people to update to it, I asked dan a few weeks ago to add throwbacks to the error calls in all the APIs and he did, so finally there will be less 'problems' with APIs and more problems with peoples scripts which they'll realise and fix. fingers crossed again.
Edited on 16 March 2014 - 01:16 AM
Ghifari160 #5
Posted 22 March 2014 - 11:55 PM
I swear i already write there's everything that I need in there! Image in the right path and right format. I tried everything.
Lyqyd #6
Posted 23 March 2014 - 01:28 AM
What's the error? Clearly, not everything is correct, so at least help us narrow down what's wrong.
Dayrider10 #7
Posted 23 March 2014 - 01:34 AM
Please tell us the error. As a suggestion you could try to move the "/background.nfp" to just "background.nfp".
CometWolf #8
Posted 23 March 2014 - 01:57 AM
Please tell us the error. As a suggestion you could try to move the "/background.nfp" to just "background.nfp".
Removing the slash is considered worse, though either way works.

Last time someone had an issue with paintutils images, i suggested the following

local paintutils = setmetatable(
  {
	loadImage = function(path)
	  assert(fs.exists(path),"Attempted to load non-existent image file "..path)
	  local image = _G.paintutils.loadImage(path)
	  assert(image,"Attempted to load non image file "..path)
	  return image
	end
  },
  {
	__index = _G.paintutils
  }
)
Putting that at the top of your code should give you some clearer error messages. Provided the issue is the image file.
Dayrider10 #9
Posted 23 March 2014 - 02:15 AM
Please tell us the error. As a suggestion you could try to move the "/background.nfp" to just "background.nfp".
Removing the slash is considered worse, though either way works.

Last time someone had an issue with paintutils images, i suggested the following

local paintutils = setmetatable(
  {
	loadImage = function(path)
	  assert(fs.exists(path),"Attempted to load non-existent image file "..path)
	  local image = _G.paintutils.loadImage(path)
	  assert(image,"Attempted to load non image file "..path)
	  return image
	end
  },
  {
	__index = _G.paintutils
  }
)
Putting that at the top of your code should give you some clearer error messages. Provided the issue is the image file.

Thanks for letting me know. I thought it was better to do that. Maybe I will have to change my code to fix that up. Thanks. As for this I can't really tell you. Try to make the file a normal paint file with the default paint instead of .nfp. Like this

    bgimg = paintutils.loadImage("background")
    paintutils.drawImage(bgimg ,1 ,1)
Ghifari160 #10
Posted 29 March 2014 - 12:05 AM
Please tell us the error. As a suggestion you could try to move the "/background.nfp" to just "background.nfp".
Removing the slash is considered worse, though either way works.

Last time someone had an issue with paintutils images, i suggested the following

local paintutils = setmetatable(
  {
	loadImage = function(path)
	  assert(fs.exists(path),"Attempted to load non-existent image file "..path)
	  local image = _G.paintutils.loadImage(path)
	  assert(image,"Attempted to load non image file "..path)
	  return image
	end
  },
  {
	__index = _G.paintutils
  }
)
Putting that at the top of your code should give you some clearer error messages. Provided the issue is the image file.
I tried the same thing, but it still doesn't work for me. It says the image is not there, but I put the image there.

local paintutils = setmetatable(
  {
    loadImage = function(path)
      assert(fs.exists(path), "Attempted to load non-existent image file"..path)
      local image = _G.paintutils.loadImage(path)
      assert(image,"Attempted to load non image file"..path)
      return image
    end
  },
  {
    __index = _G.paintutils
  }
)

local version = "1.0 BETA"
local updateUrl = ""
local img = paintutils.loadImage("test")


function init()
   paintutils.drawImage(img, 1, 1) 
end

init()
CometWolf #11
Posted 29 March 2014 - 12:25 AM
Your picture file is in the computer root folder and called "test", correct?
Edited on 28 March 2014 - 11:27 PM
Ghifari160 #12
Posted 29 March 2014 - 08:25 PM
Your picture file is in the computer root folder and called "test", correct?
found the problem. It's fixed now.