日冕中的大图像旋转
我有一个尺寸为 1162 x 16 的图像,我想在触摸“移动相位”事件时旋转它, 问题是,当图像旋转时,它会被打乱“像素化”,尽管它没有被缩放, 我尝试使用尺寸为 128 x 128 的图像,但图像没有像素化, 难道是图片太大的原因!!
旋转会影响图像结构吗??? 任何人都知道为什么会发生这种情况???
或者如果有人有解决方法,请您帮助我。
这是使其成为正方形后更新的代码:
local bck = display.newRect (0,0,display.contentWidth,display.contentHeight)
bck.x = display.contentWidth * 0.5
bck.y = display.contentHeight * 0.5
bck:setFillColor (255,255,255)
local img = display.newImageRect ("laser1.png",1170,1170)
img.x = display.contentWidth * 0.5
img.y = display.contentHeight * 0.5
local function getRotation(PointX1,PointY1,PointX2,PointY2)
--display.getCurrentStage():setFocus ( Bug )
local atan2 = math.atan2
local pi = 3.14159265358
local deltax = PointX2 - PointX1
local deltay = PointY2 - PointY1
local currentAngle = ((atan2(deltay,deltax) )* 180.0) / pi
local rotationDigree = currentAngle - img.previousAngle;
img.previousAngle = currentAngle
return rotationDigree;
end
local function handleTouch ( event )
img.previousAngle = 1
if( event.phase == "moved" ) then
img.rotation = getRotation ( img.x , img.y , event.x , event.y )
end
end
Runtime:addEventListener ("touch",handleTouch)
i have an image with size 1162 x 16 which i want to rotate on the touch "moved phase" event ,
the problem is that when the image rotates it gets scrambled "pixelated", although it is not getting scaled ,
i tried with an image of size 128 x 128 but the image was not pixelated,
could it be due to the large size of the image !!
does the rotation affect the image structure???
anyone has an idea why that happens???
or if anyone has a workaround ,, would you please help me with that .
here is the updated code after making it square :
local bck = display.newRect (0,0,display.contentWidth,display.contentHeight)
bck.x = display.contentWidth * 0.5
bck.y = display.contentHeight * 0.5
bck:setFillColor (255,255,255)
local img = display.newImageRect ("laser1.png",1170,1170)
img.x = display.contentWidth * 0.5
img.y = display.contentHeight * 0.5
local function getRotation(PointX1,PointY1,PointX2,PointY2)
--display.getCurrentStage():setFocus ( Bug )
local atan2 = math.atan2
local pi = 3.14159265358
local deltax = PointX2 - PointX1
local deltay = PointY2 - PointY1
local currentAngle = ((atan2(deltay,deltax) )* 180.0) / pi
local rotationDigree = currentAngle - img.previousAngle;
img.previousAngle = currentAngle
return rotationDigree;
end
local function handleTouch ( event )
img.previousAngle = 1
if( event.phase == "moved" ) then
img.rotation = getRotation ( img.x , img.y , event.x , event.y )
end
end
Runtime:addEventListener ("touch",handleTouch)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的图像不是正方形的。这意味着当您旋转 90 度(例如)时,您会尝试将 16 x 1162 图像放入 1162 x 16 的空间中。
这意味着图像在一个维度上被挤压,而在另一个维度上被拉伸。
您需要将源图像和目标图像设置为 1162 x 1162,并添加边框,边框可以是透明的,也可以是原始图像中没有的某种已知颜色,以便在旋转完成后可以将其删除。
128 x 128 的测试图像有效,因为它是正方形的。
Your image is not square. This means that when you rotate by 90 degrees (say) you are trying to fit a 16 x 1162 image into a space that's 1162 x 16.
This means that the image is being squashed in one dimension and stretched in the other.
You need to make both the source and target images 1162 x 1162 adding a border, either transparent or some known colour not in the original image so you can remove it once the rotation is complete.
The test image of 128 x 128 works because it's square.