Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Friday, January 30, 2009 5:43:54 AM(UTC)

NoahFN  
NoahFN

Groups: Registered
Posts: 4


I'm trying to get the bits out of an LBitmapBase object and haven't had any luck.

As a test I'm loading a bitmap into a LBitmapBase object, putting the bits from that into a buffer and creating a new LBitmapBase object with the same bits. When I save the new bitmaps I get nothing but black.

Below is my test code:

L_INT res = m_BitmapBase.Load(TEXT("C:\\Storage\\LabRD\\Test.bmp"));
    DWORD size = m_BitmapBase.GetBytesPerLine()*m_BitmapBase.GetHeight();
    LBuffer Buffer(size);
    LMemoryFile MemFile(&m_BitmapBase);
    L_SIZE_T memorySize = (m_BitmapBase.GetBytesPerLine()*m_BitmapBase.GetHeight());
    SAVEFILEOPTION saveFileOption;
    MemFile.GetDefaultSaveFileOption(&saveFileOption, sizeof(saveFileOption));
    L_INT nRet = MemFile.SaveBitmapBuffer(&Buffer, &memorySize, FILE_BMP, m_BitmapBase.GetBitsPerPixel(), ABCQ_LOSSLESS, &saveFileOption);
    unsigned char *puchPixelData = (unsigned char*)Buffer.Lock();

    LBitmapBase testBitmap(m_BitmapBase.GetWidth(), m_BitmapBase.GetHeight(), m_BitmapBase.GetBitsPerPixel());
    testBitmap.SetDataPointer(puchPixelData, (m_BitmapBase.GetBytesPerLine()*m_BitmapBase.GetHeight()));
    testBitmap.Save(TEXT("C:\\Storage\\LabRD\\TestSave1.bmp"), FILE_BMP, m_BitmapBase.GetBitsPerPixel(), ABCQ_LOSSLESS, MULTIPAGE_OPERATION_OVERWRITE);

Any help would be appreciated. Thanks!
   
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Sunday, February 1, 2009 6:22:47 AM(UTC)

Adam Boulad  
Guest

Groups: Guests
Posts: 3,022

Was thanked: 2 time(s) in 2 post(s)

Did you try to use the LBitmapBase::GetRow to copy the image data to the specified buffer?
Also, what version of LEADTOOLS (14.5, 15, 16, etc.) are you using?
 
#3 Posted : Monday, February 2, 2009 4:45:17 AM(UTC)

NoahFN  
NoahFN

Groups: Registered
Posts: 4


 Adam Boulad wrote:Did you try to use the LBitmapBase::GetRow to copy the image data to the specified buffer?
Also, what version of LEADTOOLS (14.5, 15, 16, etc.) are you using?

I have tried calling GetRow and have not been successful.

I'm using version 16. I have an evaluation license.

 

 
#4 Posted : Monday, February 2, 2009 7:11:59 AM(UTC)

Adam Boulad  
Guest

Groups: Guests
Posts: 3,022

Was thanked: 2 time(s) in 2 post(s)

Noah,
I took another look at your code and there are some inconsistencies. For example, when you use MemFile.SaveBitmapBuffer to store a FILE_BMP into the buffer, you are saving a full Windows BMP file including its bitmap file header. This is not the same thing as the bitmap bits alone.

This means you cannot use the same data with testBitmap.SetDataPointer because the data pointer should only contain bitmap bits.

Also, testBitmap.SetDataPointer can only be used with TYPE_USER bitmaps but you are using a constructor of LBitmapBase that creates a conventional bitmap (the default setting) and not a user bitmap.

One way to store bitmap bits alone is to use the FILE_RAW format instead of FILE_BMP when calling the Save??? functions.
 
#5 Posted : Wednesday, February 4, 2009 6:21:17 AM(UTC)

NoahFN  
NoahFN

Groups: Registered
Posts: 4


Adam,

Can you elaborate on the TYPE_USER bitmap issue. I don't understand what you mean by that and I don't see a reference to it in the LBitmap portion of the C++ class library help.

So would the following code get just the bitmap bits out of the image? (By changing FILE_BMP to FILE_RAW)

L_INT nRet = MemFile.SaveBitmapBuffer(&Buffer, &memorySize, FILE_RAW, m_BitmapBase.GetBitsPerPixel(), ABCQ_LOSSLESS, &saveFileOption);

unsigned char *puchPixelData = (unsigned char*)Buffer.Lock();

 

 

 
#6 Posted : Thursday, February 5, 2009 7:35:41 AM(UTC)

Adam Boulad  
Guest

Groups: Guests
Posts: 3,022

Was thanked: 2 time(s) in 2 post(s)

If you use the TYPE_USER flag when you create the bitmap, you will be responsible for maintaining and ultimately freeing the data pointer.

About saving using MemFile.SaveBitmapBuffer(... FILE_RAW ..), yes, this will give you the bitmap pixels without a palette or any headers. Please note that the ABCQ_LOSSLESS flag here is harmless but is also meaningless. This flag is only used with the ABC file format, not with RAW or BMP files.
 
#7 Posted : Monday, February 9, 2009 9:22:32 AM(UTC)

NoahFN  
NoahFN

Groups: Registered
Posts: 4


It appears as though everything is working now. I have been able to get the bits successfully, however, the resulting saved test image is flipped upside down and skewed by 45 degrees.

Any ideas as to what I might be doing wrong?

 
#8 Posted : Tuesday, February 10, 2009 5:23:49 AM(UTC)

Adam Boulad  
Guest

Groups: Guests
Posts: 3,022

Was thanked: 2 time(s) in 2 post(s)

Flipping is most likely caused by incorrect view perspective (orientation) flag. The source could be TopLeft and the destination BottomLeft, or the other way around.

The skewing effect is probably caused by failing to use the correct value for the BytesPerLine parameter. This could happen if you neglect the unused bits at the end of each line. These unused bits are added to make the number of bytes an exact multiple of four. This means a line of 90 pixels at 24-bits will have 270 bytes for the data (90 * 3), plus 2 bytes (16 bits) of un-used space in each line.
 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.103 seconds.