I am using an example from MSDN, but I get "'CImage' : undeclared identifier"?
CImage myimage;
// load existing image
myimage.Load("image.bmp");
// save an image in BMP format
myimage.Save("c:\image1.bmp");
// save an image in BMP format
myimage.Save("c:\image2",ImageFormatBMP);
// save an image in JPEG format
myimage.Save("c:\image3.jpg");
// save an image in BMP format, even though jpg file extension is used
myimage.Save("c:\image4.jpg",ImageFormatBMP);
The documentation for CImage shows that it is defined in atlimage.h. You must #include that in your source. Also note the warning that you must include afxstr.h first to avoid errors.
Related
Using Embarcadero C++Builder, does anyone know how to manually load a .bmp file into a TSpeedButton using the Glyph property, setting a path to the image, not with the Object Inspector?
The Glyph property is a TBitmap, so you can use the TBitmap::LoadFromFile() method to load a new glyph from a file:
speedbutton->Glyph->LoadFromFile("filename.bmp");
Note: "Glyph can provide up to four images within a single bitmap. All images must be the same size and next to each other in a horizontal row."
I am trying to read an image into a QImage from a partially downloaded file, to show progress as it downloads. With jpg images, I can display the content that has downloaded so far, but with png files I get the following error:
libpng error: Read Error
and then trying to use the QImage results in failure with:
Image is a null image
If I save the partially downloaded file, I can open it with every program I've tried, showing though sometimes logging a warning, like with gimp:
* (file-png:25459): WARNING **: Error loading PNG file: Read Error
Is there a way to get the same behavior with png's as with jpg's where the partially downloaded file is loaded and displayed as just the top half of the image? Is there a better way to do this with QImage? I have access to the image data in RAM as well, plus the length of how much has been received, if that helps.
I am trying to read a bmp file using below function in c++
HANDLE hBmp = LoadImage(0, L"C:\\Users\\abhinay\\Desktop\\Sample.bmp", IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE);
In my scenario the sample.bmp is a QRCode which is generated by a 3rd part QRCode library. When i try to read QRCode generated with above "LoadImage" function i get hBmp as "NULL".
I opened QRCode image "sample.bmp" with MS paint and saved it as .bmp in 24-bit Bitmap and now i am able to load the file using the same "LoadImage" function above.
Can you please help why the bmp file was not loaded in the first case and how can i make the the generated QRCode image to be loaded properly loaded using "LoadImage" function without the need of converting into 24-bit Bitmap image using MS Paint. Also let me know if its easy to print a .jpg or .png image instead of a .bmp file.
Thanks
Abhinay
Edit
I have tried using "GetLastError()" as mentioned below
HANDLE hBmp = LoadImage(NULL, bmpfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
if (hBmp == NULL)
{
DWORD dw = GetLastError();
if (dw == NULL)
{
MessageBoxA(NULL, "get last error is null", "ABHINAY", MB_OK | MB_TOPMOST);
}
else
{
MessageBoxA(NULL, "get last error is not null", "ABHINAY", MB_OK | MB_TOPMOST);
}
}
And i get the error message "get last error is null".
Can you please help why the bmp file was not loaded in the first case?
There are lots of variations of BMP format. It's quite possible that the original image was in a variant that LoadImage cannot directly convert to a DIB. So you converted it in Paint to a BMP variant that it could open.
In particular, there are variants where raw PNG of JPG data can be packed into a BMP container. This is typically used to pass the compressed image data directly to a printer that can decompress itself. (In my experience, only a few printers actually support this.) I don't think the GDI API can actually do much else with BMPs of this type. Paint, on the other hand, has codecs for PNG and JPG, so I'd expect its repertoire might include those formats, even when they're packed in a BMP header.
how can i make the the generated QRCode image to be loaded properly loaded using "LoadImage" function without the need of converting into 24-bit Bitmap image using MS Paint.
I don't think you'll be able to do it with LoadImage without converting the file. Modern versions of Windows have other APIs that can load BMPs (and PNG and JPG), so you might try one of these.
GDI+ (probably the simplest)
WIC
OLE (probably the most complex, especially if you're not used to COM)
Also let me know if its easy to print a .jpg or .png image instead of a .bmp file.
If you use one of the APIs I listed to load the image, printing it should be pretty straightforward.
I have a C++ project which uses Windows Animation Manager with Direct2D under Visual Studio 2010 to implement image sparkled animation.
But when I load a png image, the transparent can’t display correctly.
I use IWICImagingFactory and IWICBitmap to load the png image, and then create a D2D bitmap from the WIC bitmap. The D2D1_PIXEL_FORMAT’s alphaMode set as D2D1_ALPHA_MODE_PREMULTIPLIED and format set as DXGI_FORMAT_B8G8R8A8_UNORM. It seems only opaque and transparent without semitranslucent. And I try to change the D2D1_PIXEL_FORMAT’s alphaMode to D2D1_ALPHA_MODE_STRAIGHT but it doesn’t work. I also follow the sample code from MSDN ( http://msdn.microsoft.com/en-us/library/windows/desktop/ee719658(v=vs.85).aspx ), but nothing display. Can someone help me that how to load a png image and transfer to ID2D1Bitmap with correct alpha value? Thanks!
I already solved my question from the example code under \Microsoft SDKs\Windows\v7.1\Samples\multimedia\wic\wicviewerd2d. The important keyword is GUID_WICPixelFormat32bppPBGRA when initialize the IWICFormatConverter object.
I'm trying to create a splash screen that will show transparent png background. So at first I need to load png file into format that is acceptable for the UpdateLayeredWindow calls (basically HBITMAP with RGBA format).
At the moment, I've found Windows Imaging Component, but that does not work for VS2005 (which is mandatory requirement). Using some additional libraries is also a problem.
I've heard that GDI+ can do the trick, but I can't find a proper example unfortunately :( Can anyone help?