Conforming a bitmap image to a particular resolution without resizing artefacts, and storing it as a PNG image in a database
-
Hi guys, I need to do the following in an application I'm developing using C++ and MFC: 1. Open an image of any of the major image formats (say Windows bitmap, Jpeg and PNG). 2. Conform it to a certain resolution. I have a strong preference for doing so without creating any resizing artefacts. I would like the result to be similar to the result you get by resizing an image in Photoshop, rather than the result you get when internet explorer renders and image at a resolution different to that of the image itself (that creates unsettling artefacts). 3. Convert to PNG, and then get a char pointer to a buffer containing the PNG file, so I can serialise the image as a blob in a database for later retrieval. 4. Retrieve the image from the database, and re-create the PNG image to be displayed in my MFC application. How might this be best achieved? I'm not necessarily looking for precise instructions - guidelines may be enough. I have a preference for using lightweight third-party libraries distributed under liberal open source licenses (i.e. not a GPL library). If boost.GIL (generic image library) can help, I'd certain be receptive to that, as I already use boost a lot. That said, given my relatively simple needs even that may be overkill, Regards, Sternocera
-
Hi guys, I need to do the following in an application I'm developing using C++ and MFC: 1. Open an image of any of the major image formats (say Windows bitmap, Jpeg and PNG). 2. Conform it to a certain resolution. I have a strong preference for doing so without creating any resizing artefacts. I would like the result to be similar to the result you get by resizing an image in Photoshop, rather than the result you get when internet explorer renders and image at a resolution different to that of the image itself (that creates unsettling artefacts). 3. Convert to PNG, and then get a char pointer to a buffer containing the PNG file, so I can serialise the image as a blob in a database for later retrieval. 4. Retrieve the image from the database, and re-create the PNG image to be displayed in my MFC application. How might this be best achieved? I'm not necessarily looking for precise instructions - guidelines may be enough. I have a preference for using lightweight third-party libraries distributed under liberal open source licenses (i.e. not a GPL library). If boost.GIL (generic image library) can help, I'd certain be receptive to that, as I already use boost a lot. That said, given my relatively simple needs even that may be overkill, Regards, Sternocera
Sternocera wrote:
1. Open an image of any of the major image formats (say Windows bitmap, Jpeg and PNG).
Sternocera wrote:
2. Conform it to a certain resolution. I have a strong preference for doing so without creating any resizing artefacts. I would like the result to be similar to the result you get by resizing an image in Photoshop, rather than the result you get when internet explorer renders and image at a resolution different to that of the image itself (that creates unsettling artefacts).
Sternocera wrote:
3. Convert to PNG, and then get a char pointer to a buffer containing the PNG file, so I can serialise the image as a blob in a database for later retrieval.
Again, CImage. Use the Save[^] method to save to an IStream created on an HGLOBAL[^], i.e. an IStream that writes to memory. Use a null HGLOBAL to start with, then use GetHGlobalFromStream[^] to get the HGLOBAL that the stream eventually ended up allocating. Then use GlobalSize[^] to get the amount of memory used by the stream and GlobalLock[^] to access the memory.
-
Sternocera wrote:
1. Open an image of any of the major image formats (say Windows bitmap, Jpeg and PNG).
Sternocera wrote:
2. Conform it to a certain resolution. I have a strong preference for doing so without creating any resizing artefacts. I would like the result to be similar to the result you get by resizing an image in Photoshop, rather than the result you get when internet explorer renders and image at a resolution different to that of the image itself (that creates unsettling artefacts).
Sternocera wrote:
3. Convert to PNG, and then get a char pointer to a buffer containing the PNG file, so I can serialise the image as a blob in a database for later retrieval.
Again, CImage. Use the Save[^] method to save to an IStream created on an HGLOBAL[^], i.e. an IStream that writes to memory. Use a null HGLOBAL to start with, then use GetHGlobalFromStream[^] to get the HGLOBAL that the stream eventually ended up allocating. Then use GlobalSize[^] to get the amount of memory used by the stream and GlobalLock[^] to access the memory.
Stuart, Good answer, great tagline, Regards, Sternocera
-
Sternocera wrote:
1. Open an image of any of the major image formats (say Windows bitmap, Jpeg and PNG).
Sternocera wrote:
2. Conform it to a certain resolution. I have a strong preference for doing so without creating any resizing artefacts. I would like the result to be similar to the result you get by resizing an image in Photoshop, rather than the result you get when internet explorer renders and image at a resolution different to that of the image itself (that creates unsettling artefacts).
Sternocera wrote:
3. Convert to PNG, and then get a char pointer to a buffer containing the PNG file, so I can serialise the image as a blob in a database for later retrieval.
Again, CImage. Use the Save[^] method to save to an IStream created on an HGLOBAL[^], i.e. an IStream that writes to memory. Use a null HGLOBAL to start with, then use GetHGlobalFromStream[^] to get the HGLOBAL that the stream eventually ended up allocating. Then use GlobalSize[^] to get the amount of memory used by the stream and GlobalLock[^] to access the memory.
Stuart Dootson wrote:
cubic Interpolation[^]
Stuart, Can you suggest a practical way to use Bicubic interpolation to resize my CImage? Obviously it's preferable to use some proven third party library rather than re-inventing the wheel. Again, *any* guidance you can offer is helpful, I'm not necessarily looking for step-by-step instructions. Google has not been helpful here, Regards, Sternocera
-
Stuart Dootson wrote:
cubic Interpolation[^]
Stuart, Can you suggest a practical way to use Bicubic interpolation to resize my CImage? Obviously it's preferable to use some proven third party library rather than re-inventing the wheel. Again, *any* guidance you can offer is helpful, I'm not necessarily looking for step-by-step instructions. Google has not been helpful here, Regards, Sternocera
CxImage[^] has plenty of interpolation algorithms. After some research, Lanczos resampling may be better than bicubic - CxImage does both. [edit]FreeImage[^] is another image processing library with interpolation. The documentaton includes a section on choosing the right interpolation algorithm, which could be handy[/edit]
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Stuart Dootson wrote:
cubic Interpolation[^]
Stuart, Can you suggest a practical way to use Bicubic interpolation to resize my CImage? Obviously it's preferable to use some proven third party library rather than re-inventing the wheel. Again, *any* guidance you can offer is helpful, I'm not necessarily looking for step-by-step instructions. Google has not been helpful here, Regards, Sternocera
You might try my DLL [^]. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]