Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: EBitmapLoadingFailed


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 5 - Last Post: Nov 15, 2015 2:41 AM Last Post By: bernard roussely
bernard roussely

Posts: 106
Registered: 2/8/05
EBitmapLoadingFailed  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 6, 2015 7:34 AM
Hello,

I've an EBitmapLoadingFailed exception with both XE8 and XE10. The code is the following:

        // in .h
	TImageControl *QRCodeImage1;
        // in .cpp
 
		try {
			QRCodeImage1->LoadFromFile(outputfile1);
		} catch (...) {
		}

"outputfile1" path has been verified with FileExists and is a simple QR code showing "Test" (other BMP files fail too).
This code works fine on Windows with the same BMP file but raises EBitmapLoadingFailed on Android.

I have seen some bug reports relating to a similar issue with XE7 and posted a new bug for XE10.
Anyone with a fix or an idea of what is wrong?

bernard
Yilmaz Yoru


Posts: 167
Registered: 1/1/03
Re: EBitmapLoadingFailed  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 10, 2015 12:52 AM   in response to: bernard roussely in response to: bernard roussely
I am not sure what you are doing but i think you can use bitmap by using TBitmap or TPicture
	TBitmap *QRCodeImage1=new(TBitmap);
 
	TBitmap *QRCodeImage1;
	try {
 			QRCodeImage1->LoadFromFile(outputfile1);
	                 Image1->Picture->Bitmap->Assign(bmp);
 		} catch (...) {
 		}


or u can directly load to Image if you have by using
Image1->Picture->Bitmap->LoadFromFile(outputfile1);

may be in your codes there might be

TImageControl *QRCodeImage1=new(TImageControl);


--
bernard roussely

Posts: 106
Registered: 2/8/05
Re: EBitmapLoadingFailed  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 10, 2015 5:03 AM   in response to: Yilmaz Yoru in response to: Yilmaz Yoru
Thanks.

To be more precise, I have a TImageControl on the application form and this works fine on Windows. Android is the issue.

bernard
Yilmaz Yoru


Posts: 167
Registered: 1/1/03
Re: EBitmapLoadingFailed  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 10, 2015 7:18 AM   in response to: bernard roussely in response to: bernard roussely
Look what is that file ? a bitmap? *.bmp, *.jpg ?

May be you should use this,you should load bitmap to its bitmap if it is a bitmap.

	TImageControl *QRCodeImage1;
        // in .cpp
 
		try {
                        // QRCodeImage1->LoadFromFile(outputfile1); 
			   QRCodeImage1->Bitmap->LoadFromFile(outputfile1);
		} catch (...) {
		}  


Please check this if it works or not.

I dont have cable and i cant test ony my LG now and a busy day today if not im gonna check on IDE tomorrow.

--
Yilmaz
bernard roussely

Posts: 106
Registered: 2/8/05
Re: EBitmapLoadingFailed  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 10, 2015 8:53 AM   in response to: Yilmaz Yoru in response to: Yilmaz Yoru
Hi Yilmaz,

It doesn't work either. Now, I have converted the file to PNG and it loads fine (but I need the BMP for my app).

Conclusion, there is a bug with BMP files on Android.

Thanks for your time,

bernard

P. S. : the official answer is BMP is neither supported on Android nor on iOS (see http://docwiki.embarcadero.com/Libraries/Seattle/en/FMX.Graphics.TBitmapCodecManager).
bernard roussely

Posts: 106
Registered: 2/8/05
Re: EBitmapLoadingFailed  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 12, 2015 4:24 AM   in response to: bernard roussely in response to: bernard roussely
Here is a fix when the pixel data is taken from MyPixelDataBuffer. This could most probably be improved.
The file extension has to be supported by Embarcadero on Android and iOS to be loaded back (e.g., PNG) on those OSes.

#define PIXEL_DENSITY	32	// Used to generate "dense" bitmaps and sharpens the image when zoomed out. Should be at leat 8. The bigger the slower!
 
int x, y, i, j;
TBitmapData MyBitData;
TMapAccess MyAccess = (TMapAccess)2; // TMapAccess maReadWrite
 
unsigned int	bmWidth;
unsigned char	*pSourceData;
 
	bmWidth = SomeWidth; // the image will be square
	// initializes the image bitmap canvas
	MyImage->Bitmap = new TBitmap(bmWidth * PIXEL_DENSITY, bmWidth * PIXEL_DENSITY);
	pSourceData = (unsigned char *)MyPixelDataBuffer; // points to the raw data generated elsewhere
 
	if(MyImage->Bitmap->Map(MyAccess, MyBitData)) {
		try {
			for(x = 0; x < bmWidth; x++) {
				for(y = 0; y < bmWidth; y++) {
					if(*pSourceData & (char)1) { // checks if a pixel has some color other than white in this example
						for(i = 0; i < PIXEL_DENSITY; i++) { // a pixel will be copied  PIXEL_DENSITY x  PIXEL_DENSITY times
							for(j = 0; j < PIXEL_DENSITY; j++) {
								MyBitData.SetPixel(x * PIXEL_DENSITY + i, y * PIXEL_DENSITY + j, TAlphaColors::Black);
							}
						}
					}
					pSourceData++;
				}
			}
		}
		catch(...) {
		}
		MyImage->Bitmap->Unmap(MyBitData);
	}
	MyImage->Bitmap->SaveToFile(outputfile); // outpufile has PNG extension
}


bernard
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02