newImage and newImageRect - bugg - showstopper!

Hi,

I am having almost two identical images and one of them gets blurred. I am using newImage - so I then tried newImageRect and voila the image looks sharp and crispy again.

So next step was to add setReferencePoint, and then it got blurred again?

I am using PNG 24Bit images with transparency…

Code is:

local btnPrev = display.newImageRect(“assets/Gfx_GUI_Sign_Prev.png”,107,73)
–btnPrev:setReferencePoint( display.TopLeftReferencePoint )
btnPrev.x = 10
btnPrev.y = 680

Please help, this is a showstopper! [import]uid: 81188 topic_id: 22353 reply_id: 322353[/import]

I think I read somewhere that this can happen if the dimensions of your image are not divisible by two. Try setting that to 108, 74 and see if that fixes it.

[import]uid: 93133 topic_id: 22353 reply_id: 89096[/import]

All those uppercase and lowercase letters in the file name are just asking for a typo. Are you sure the low and high resolution assets have the same name? [import]uid: 61899 topic_id: 22353 reply_id: 89099[/import]

I am only using highres the target is iPad :slight_smile:

[import]uid: 81188 topic_id: 22353 reply_id: 89109[/import]

Your image files must - MUST - be in at least divisible by 2 if you want them to remain crisp.

Why? Because even if you are not scaling your images, they are still being mapped to Corona’s internal coordinate system. An odd-sized image will result in a fractional pixel value, which will then be rendered as an anti-aliased edge.

Best be safe and make them powers of 2, though. [import]uid: 120 topic_id: 22353 reply_id: 89114[/import]

Please advise. I am having a similar problem, only I am using IDENTICAL files.

  • Both files loaded with newImageRect.
  • The first file is loaded because it is called myimage@2x.jpg, and I’ve asked to load myimage.jpg
  • The second file (a duplicate of the first 2x file), is loaded using its own name, myimage-hires.jpg

They should look identical. They are used in identical ways, on two identical pages of an eBook. However, the one loaded directly, i.e. myimage-hires.jpg, is soft and fuzzy, while the first (@2x) is sharp and clear.

The files are identical 2048x1536 pixels, JPG files.

[import]uid: 37366 topic_id: 22353 reply_id: 100215[/import]

The following might be a solution to using 2x images. Do you own checking to see if the screen is 2x, and if so, load the 2x version of the file. THEN, scale by 50%.

It seems sharp, so far…will test more.

local high = display.newImage("image2x.jpg", true) high:scale(.5,.5) [import]uid: 37366 topic_id: 22353 reply_id: 101658[/import]

OK, here’s another way to handle this problem. This is the main code for caching image file sizes. Each time you call getImageSize, it checks whether the image is in the list, ImageInfoList. That list of sizes is stored as a JSON file in the caches directory. So, as the images are loaded, the sizes are stored, meaning the next time the image is loaded the sizes are already figured out.

It seems to speed up the loading a lot.

Just make sure the table, ImageInfoList, is accessible! Note, it is declared just before the getImageSize() function. You might want it elsewhere.

[code]

– Save/load functions

function saveData(filePath, text)

–local levelseq = table.concat( levelArray, “-” )
local file = io.open( filePath, “w” )
if (file) then
file:write( text )
io.close( file )
return true
else
print ("Error: funx.saveData: Could not create file "…tostring(filePath))
return false
end
end

function loadData(filePath)
local t = nil
–local levelseq = table.concat( levelArray, “-” )
local file = io.open( filePath, “r” )
if (file) then
t = file:read( “*a” )
io.close( file )
else
print ("funx.loadData: No file found at "…tostring(filePath))
end
return t
end

function saveTableFromFile(filePath, dataTable)

–local levelseq = table.concat( levelArray, “-” )
file = io.open( filePath, “w” )

for k,v in pairs( dataTable ) do
file:write( k … “=” … v … “,” )
end

io.close( file )
end

function loadTableFromFile(filePath)
local file = io.open( filePath, “r” )

if file then

– Read file contents into a string
local dataStr = file:read( “*a” )

– Break string into separate variables and construct new table from resulting data
local datavars = split(dataStr, “,”)

dataTableNew = {}

for i = 1, #datavars do
– split each name/value pair
local onevalue = split(datavars[i], “=”)
dataTableNew[onevalue[1]] = onevalue[2]
end

io.close( file ) – important!

– Note: all values arrive as strings; cast to numbers where numbers are expected
dataTableNew[“numValue”] = tonumber(dataTableNew[“numValue”])
dataTableNew[“randomValue”] = tonumber(dataTableNew[“randomValue”])

else
print (“no file found”)
end
end

function saveTable(t, filename, path)
if (not t or not filename) then
return true
end

path = path or system.DocumentsDirectory
–print ("funx.saveTable: save to "…filename)

local json = json.encode (t)
local filePath = system.pathForFile( filename, path )
saveData(filePath, json)
end

function loadTable(filename, path)
path = path or system.DocumentsDirectory

local filePath = system.pathForFile( filename, path )
–print ("funx.loadTable: load from "…filePath)

local t = {}
local f = loadData(filePath)
if (f and f ~= “”) then
t = json.decode(f)
end
–print (“loadTable: end”)
return t
end


– Image loading

function getScaledFilename(filename, d)
local scalingRatio = scaleFactorForRetina()
local scalesuffix = “@”…scalingRatio…“x”

– Is there an other sized version?
local suffix = string.sub(filename, string.len(filename)-3, -1)
local name = string.sub(filename, 1, string.len(filename)-4)
local f2 = name … scalesuffix … suffix

– If no scaled file, get original
if (fileExists(f2,d)) then
filename = f2
return filename, scalingRatio
else
return filename, 1
end
end

– Get an image size (height, width)
– We need this to use it for display.newImageRect
– Let’s keep a list of image sizes so we can avoid double-loading.align
– Every time we load, save the size to a list we maintain.

local ImageInfoList = loadTable(“images_info.json”, system.CachesDirectory) or {}

function getImageSize(f,d)
d = d or system.ResourceDirectory

– load info table, if not loaded
if (not ImageInfoList) then
ImageInfoList = loadTable(“images_info.json”, system.CachesDirectory)
end

– Check the sizes list for this image
if (ImageInfoList[f]) then
return ImageInfoList[f].width, ImageInfoList[f].height
else
– add to the list
local i = display.newImage(f,d,true)
local w = i.contentWidth
local h = i.contentHeight
i:removeSelf()
i = nil

ImageInfoList[f] = { width = w, height = h }
saveTable(ImageInfoList, “images_info.json”, system.CachesDirectory)
return w,h
end
end
[/code] [import]uid: 37366 topic_id: 22353 reply_id: 101709[/import]

I’m seeing more posts about blurry or other weird image “scaling” issues in the past month than I recall seeing in months. I think there is a bug somewhere in a daily build, possibly since the introduction of the new image sheet APIs. Hopefully Ansca is investigating this… it’s unlikely that we are all “wrong” in our usage and image composition and scaling. [import]uid: 9747 topic_id: 22353 reply_id: 101723[/import]

Yup, there are some graphics bug regressions in the latest daily builds. If you haven’t already, submit a bug and attach a simple project. We’re about to start a bug cycle, and we’ll be giving preference to bugs with test cases that can be easily reproduced.

http://developer.anscamobile.com/content/bug-submission [import]uid: 26 topic_id: 22353 reply_id: 101732[/import]

Ive had exactly the same issue all day seems to occur whenever I remove children from an image group, for some reason will always make the last child added to the group flash randomly in places it should not tested in multiple places, is defo a bug somewhere.

I managed to solve the issue by placing a completely blank image/space from the imagaesheet into the imagegroup before it reduces in size, then the randomly flashing image would not be visible anymore. Big pain but it worked. [import]uid: 118379 topic_id: 22353 reply_id: 103175[/import]

@Beloudest: Please see my post on your topic here: http://developer.anscamobile.com/forum/2012/04/25/image-groups-images-randomly-flashing [import]uid: 84637 topic_id: 22353 reply_id: 103194[/import]