Re: Question about QImage
The const bits() function does not return a deep copy
Re: Question about QImage
How can I call the bits() const instead the bits() function ?
Re: Question about QImage
Using const uchar * of course.
But:
I would probably do this differently. I would keep track of the data and delete it at the appropriate place.
You could keep a reference list of data and images. When the reference drops below 0, delete the data.
Re: Question about QImage
Sorry, but I want to understand a thing.
How can I call the overaloaded function bits() const instead the bits()?!?!
It depends about the constructor of the qimage??
Ex.
qimage.bits() which values returns ?
Re: Question about QImage
Code:
uchar *data = myImage.bits(); // Deep copy
const uchar *data = myImage.bits(); // No deep copy
Re: Question about QImage
Just to be clear, the non-const bits() method does not create a deep copy of the memory unless there are other copies of the image sharing the same data. All it does is call detach(). If you are sure that that's the only copy of the image then calling it will work. If not then you cannot safely delete the memory in any case. I would agree that there are better ways to do this. In most situations the best thing to do is to allow QImage to manage its own memory.
Re: Question about QImage
Quote:
Just to be clear, the non-const bits() method does not create a deep copy of the memory unless there are other copies of the image sharing the same data. All it does is call detach(). If you are sure that that's the only copy of the image then calling it will work. If not then you cannot safely delete the memory in any case. I would agree that there are better ways to do this. In most situations the best thing to do is to allow QImage to manage its own memory.
How is it possible to allow QImage to manage its own memory?
Re: Question about QImage
Quote:
Originally Posted by
paolom
How is it possible to allow QImage to manage its own memory?
Don't use the constructor that takes an existing buffer. If you use e.g. QImage ( int width, int height, Format format ) it will manage its own memory. Obviously this is sub-optimal if you happen to already have the image data in memory, but it will make resource management much easier.
Re: Question about QImage
Quote:
Don't use the constructor that takes an existing buffer. If you use e.g. QImage ( int width, int height, Format format ) it will manage its own memory. Obviously this is sub-optimal if you happen to already have the image data in memory, but it will make resource management much easie
I've an existing buffer in memory.
I can use the QImage ( int width, int height, Format format ) constructor also, but how I can fill the qimage with my buffer and leave the QImage manage its own memory ?!
Ex. setPixel() ???????