简体   繁体   English

在 Qt/QML 中绘制图像是什么意思?

[英]What do you mean by drawing an image in Qt/QML?

https://doc.qt.io/archives/qt-5.11/qpainter.html#drawImage-5https://doc.qt.io/archives/qt-5.11/qpainter.html#drawImage-5

void QPainter::drawImage(const QRect &rectangle, const QImage &image)

Draws the given image into the given rectangle.将给定的图像绘制到给定的矩形中。

They have used the word draw for a reason.他们使用draw这个词是有原因的。 I believe if I have an image I can myself put it in a rectangle.我相信如果我有一个图像,我可以自己把它放在一个矩形中。 I don't need a specialized function for that.为此,我不需要专门的 function。

What does this function do besides putting the image in the rectangle?这个function除了把图片放到矩形里面还有什么作用?

Is it somehow more efficient than the following?它是否比以下更有效?

Rectangle
{
   height: 100; width: 100
   Image
   {
      source: "xyz.png"
   }
}

Short answer: You are confusing concepts: QImage is not the same as QML Image item, and similar for QRect and Rectangle.简短回答:您混淆了概念:QImage 与 QML Image 项目不同,QRect 和 Rectangle 也类似。

Long answer:长答案:

QImage is a class that allows to represent an image, in simple words it is a container of the bytes that represent the image and how those bytes are related. QImage 是一个允许表示图像的 class,简单来说,它是表示图像的字节以及这些字节如何相关的容器。 Instead Image is an Item that allows displaying an image.相反,Image 是一个允许显示图像的 Item。

QPainter's drawImage method paints a rectangle over a QImage (changes a few bytes to represent the rectangle). QPainter 的 drawImage 方法在 QImage 上绘制一个矩形(更改几个字节来表示矩形)。 Instead in your code you are creating an Item Rectangle where you place an Item Image.相反,在您的代码中,您正在创建一个放置项目图像的项目矩形。

Facts:事实:

  • QImage and QRect are not visual elements QImage 和 QRect 不是视觉元素

  • QImage can be taken as a base for painting a visual element. QImage 可以作为绘制视觉元素的基础。

  • QPainter is used for low level painting unlike QML items (Items are painted using QPainter)与 QML 项目不同,QPainter 用于低级绘画(项目使用 QPainter 绘画)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM