• 3730阅读
  • 0回复

[提问]loadImage加载图片问题 [复制链接]

上一主题 下一主题
离线jloveforever
 

只看楼主 倒序阅读 楼主  发表于: 2015-11-14
今天我用Canvas画布来绘制图片,但是使用了loadImage却失败了,所以图片并没有绘制,但却不知道为什么失败了?求帮助



import QtQuick 2.3
import QtGraphicalEffects 1.0
import QtQuick.Window 2.0
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
Rectangle {
    id:rect
    implicitWidth :480
    implicitHeight: 480
    radius:implicitHeight/2
    //    color:"blue"


    //        Image {
    //            id: background
    //            source: "qrc:/image/background.jpg"
    //            anchors.fill: rect
    //        }
   Canvas {
        width: 480
        height: 480
        opacity: 1
        clip: false
        contextType: qsTr("2d")
        anchors.left:rect.left
        anchors.top: rect.top
        anchors.bottom: rect.bottom
        //        property var  image:"qrc:/image/background.jpg"

        onPaint: {
            context.save()
            context.beginPath()
            context.lineWidth=2
            context.strokeStyle="blue"
            context.fillStyle=Qt.rgba(0.3,0.5,0.7,0.3)
            //            context.drawImage("qrc:/image/background.jpg",0,0)
            context.arc(180,150,0,Math.PI*2,true)
            context.closePath()
            context.clip()
            context.drawImage("qrc:/image/background.jpg",0,0)
            context.stroke()
            context.fill()
            context.restore()
        }
        Component.onCompleted:
            if(!isImageError("qrc:/image/background.jpg")){
                console.log("error")
            }
            else
                loadImage("qrc:/image/background.jpg")
        onImageLoaded: requestPaint()
    }
}
快速回复
限100 字节
 
上一个 下一个