i don’t like to show the whole picture.i just want to show part of the picture.
?
thx [import]uid: 45977 topic_id: 19658 reply_id: 319658[/import]
Two thoughts:
Use the image as the sheet for a sprite set, and set a sprite to show the section you want.
Show the picture, then draw rectangles all over it to hide the bits you don’t want. [import]uid: 108660 topic_id: 19658 reply_id: 75956[/import]
@jeff472
thx
i think the second is fit for me. [import]uid: 45977 topic_id: 19658 reply_id: 75959[/import]
also look at the mask function where you can create a complex shape that only lets a part of your image to show through. This is pretty powerful as you can use either hard edges or an alpha transparency for a blended soft edge. Masks can also move relative to the texture providing a movement effect.
I used it to show an object sliced into two pieces. It took a few minutes to achieve the effect I needed
just duplicate the original display object attach two mask images at angle of the slash and add some velocities to the objects…
It work exactly as the API so I don’t think I need to provide an example here [import]uid: 3093 topic_id: 19658 reply_id: 75958[/import]
A third scenario is offered to you. If you need more than one sections of the image to show on the same screen and you want to be able to resize it, I have used the display.save to save the image I desire and than re-display. I simply position the portion of the image I desire in the bottom right corner of the screen, save it than use this newly saved image, move the portion I want to the top left corner and save again. This new image consist of only the image I desire allowing me to play with it at will. The only problem is that the speed is not that fast but it was the only way I found to have an image that is easily manipulated. Here’s the code:
function SaveImages(sOriginalName, sImageName, nPage, nTop, nLeft, nWidth, nHeight, sSeasonNo, nPageNo)
printBegin(event, “SaveImages”)
if nResolution == 1 then
ImgGr1= display.newGroup()
ImgGr1:insert(display.newImage(sOriginalName, system.DocumentsDirectory, 0, 0, true))
scale = 1
nImageWidth = ImgGr1[1].width
nImageHeight = ImgGr1[1].height
ImgGr1[1].xScale = scale
ImgGr1[1].yScale = scale
ImgGr1[1].x=(nImageWidth)/2-(nImageWidth*nLeft)
ImgGr1[1].y=(nImageHeight)/2-(nImageHeight*nTop)
display.save(ImgGr1, sImageName…“1.jpg”)
ImgGr1:removeSelf()
ImgGr1=nil
ImgGr1 = display.newGroup()
nNewHeight = 367
nNewWidth = 512
– need to use a factor since the save appears to be saving 512 wide all the time. The regular width is 480 so by using a converter, it works perfectly.
ImgGr1:insert(display.newImage(sImageName…“1.jpg”, system.DocumentsDirectory, (display.contentWidth-((nWidth*nImageWidth)*nNewWidth/display.contentWidth)), (display.contentHeight-((nHeight*nImageHeight)*nNewHeight/display.contentHeight)), true))
display.save(ImgGr1, sImageName…".jpg")
ImgGr1:removeSelf()
ImgGr1=nil
printEnd(event, “SaveImages”)
return sImageName…".jpg"
else
tmp = display.newImage(sOriginalName, system.DocumentsDirectory, 0, 0, true)
nTmpWidth = tmp.width
nTmpHeight = tmp.height
tmp:removeSelf()
tmp = nil
ImgGr1= display.newGroup()
ImgGr1:insert(display.newRect(1, 1, 1024, 725))
ImgGr1[1]:setFillColor(0,0,0)
ImgGr1:insert(display.newImageRect(sSeasonNo…"_page-"…nPageNo…".png", system.DocumentsDirectory, nTmpWidth, nTmpHeight))
scale = 1
nImageWidth = ImgGr1[2].width
nImageHeight = ImgGr1[2].height
ImgGr1[2].xScale = scale
ImgGr1[2].yScale = scale
ImgGr1[2].x=(nImageWidth)/2-(nImageWidth*nLeft)
ImgGr1[2].y=(nImageHeight)/2-(nImageHeight*nTop)
display.save(ImgGr1, sImageName…“1.jpg”)
ImgGr1[2]:removeSelf()
ImgGr1[2] = nil
ImgGr1[1]:removeSelf()
ImgGr1[1] = nil
ImgGr1:removeSelf()
ImgGr1 = nil
tmp = display.newImage(sImageName…“1.jpg”, system.DocumentsDirectory, 0, 0, true)
nTmpWidth = tmp.width
nTmpHeight = tmp.height
nImageWidth = ((nImageWidth * nWidth)/display.contentWidth)*1024
nImageHeight = ((nImageHeight * nHeight)/display.contentHeight)*725
tmp:removeSelf()
tmp = nil
if nImageWidth > display.contentWidth or nImageHeight > display.contentHeight then
if nImageWidth/display.contentWidth > nImageHeight/display.contentHeight then
scale = display.contentWidth/nImageWidth
else
scale = display.contentHeight/nImageHeight
end
else
scale = 1
end
nImageWidth = nImageWidth * scale
nImageHeight = nImageHeight * scale
ImgGr1 = display.newGroup()
ImgGr1:insert(display.newImageRect(sImageName…“1.jpg”, system.DocumentsDirectory, 1024*scale, 725*scale))
ImgGr1[1].xScale = 1
ImgGr1[1].yScale = 1
ImgGr1[1].x = (((1024*scale)/2)+display.contentWidth)-nImageWidth
ImgGr1[1].y = (((725*scale)/2)+display.contentHeight)-nImageHeight
display.save(ImgGr1, sImageName…".jpg")
ImgGr1[1]:removeSelf()
ImgGr1[1] = nil
ImgGr1:removeSelf()
ImgGr1 = nil
printEnd(event, “SaveImages”)
return sImageName…".jpg"
end
end [import]uid: 97768 topic_id: 19658 reply_id: 78710[/import]
Masking would probably be the “Native” way to do this. [import]uid: 19626 topic_id: 19658 reply_id: 78711[/import]
I have since changed this to use sprite as their were performance issues with the previous method. Sprite only has one problem, it’s limited image size to 1024. I would need this to be much grater as I have no control over the image’s sizes that are used in my catalog. It would be a real drag to have to change the size of the images as they change often. [import]uid: 97768 topic_id: 19658 reply_id: 80673[/import]