您好,登錄后才能下訂單哦!
這篇文章主要講解了“Qt有哪些通用方法及類庫”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“Qt有哪些通用方法及類庫”吧!
//九宮格圖片 horzSplit-宮格1/3/7/9寬度 vertSplit-宮格1/3/7/9高度 dstWidth-目標圖片寬度 dstHeight-目標圖片高度 static QPixmap ninePatch(const QString &picName, int horzSplit, int vertSplit, int dstWidth, int dstHeight); static QPixmap ninePatch(const QPixmap &pix, int horzSplit, int vertSplit, int dstWidth, int dstHeight);
QPixmap QUIHelper::ninePatch(const QString &picName, int horzSplit, int vertSplit, int dstWidth, int dstHeight) { QPixmap pix(picName); return ninePatch(pix, horzSplit, vertSplit, dstWidth, dstHeight); } QPixmap QUIHelper::ninePatch(const QPixmap &pix, int horzSplit, int vertSplit, int dstWidth, int dstHeight) { int pixWidth = pix.width(); int pixHeight = pix.height(); QPixmap pix1 = pix.copy(0, 0, horzSplit, vertSplit); QPixmap pix2 = pix.copy(horzSplit, 0, pixWidth - horzSplit * 2, vertSplit); QPixmap pix3 = pix.copy(pixWidth - horzSplit, 0, horzSplit, vertSplit); QPixmap pix4 = pix.copy(0, vertSplit, horzSplit, pixHeight - vertSplit * 2); QPixmap pix5 = pix.copy(horzSplit, vertSplit, pixWidth - horzSplit * 2, pixHeight - vertSplit * 2); QPixmap pix6 = pix.copy(pixWidth - horzSplit, vertSplit, horzSplit, pixHeight - vertSplit * 2); QPixmap pix7 = pix.copy(0, pixHeight - vertSplit, horzSplit, vertSplit); QPixmap pix8 = pix.copy(horzSplit, pixHeight - vertSplit, pixWidth - horzSplit * 2, pixWidth - horzSplit * 2); QPixmap pix9 = pix.copy(pixWidth - horzSplit, pixHeight - vertSplit, horzSplit, vertSplit); //保持高度拉寬 pix2 = pix2.scaled(dstWidth - horzSplit * 2, vertSplit, Qt::IgnoreAspectRatio); //保持寬度拉高 pix4 = pix4.scaled(horzSplit, dstHeight - vertSplit * 2, Qt::IgnoreAspectRatio); //寬高都縮放 pix5 = pix5.scaled(dstWidth - horzSplit * 2, dstHeight - vertSplit * 2, Qt::IgnoreAspectRatio); //保持寬度拉高 pix6 = pix6.scaled(horzSplit, dstHeight - vertSplit * 2, Qt::IgnoreAspectRatio); //保持高度拉寬 pix8 = pix8.scaled(dstWidth - horzSplit * 2, vertSplit); //生成寬高圖片并填充透明背景顏色 QPixmap resultImg(dstWidth, dstHeight); resultImg.fill(Qt::transparent); QPainter painter; painter.begin(&resultImg); if (!resultImg.isNull()) { painter.drawPixmap(0, 0, pix1); painter.drawPixmap(horzSplit, 0, pix2); painter.drawPixmap(dstWidth - horzSplit, 0, pix3); painter.drawPixmap(0, vertSplit, pix4); painter.drawPixmap(horzSplit, vertSplit, pix5); painter.drawPixmap(dstWidth - horzSplit, vertSplit, pix6); painter.drawPixmap(0, dstHeight - vertSplit, pix7); painter.drawPixmap(horzSplit, dstHeight - vertSplit, pix8); painter.drawPixmap(dstWidth - horzSplit, dstHeight - vertSplit, pix9); } painter.end(); return resultImg; }
感謝各位的閱讀,以上就是“Qt有哪些通用方法及類庫”的內容了,經過本文的學習后,相信大家對Qt有哪些通用方法及類庫這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。