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, September 28, 2007 2:41:43 AM(UTC)

sara  
sara

Groups: Registered
Posts: 19



Hello,

I need to get the array of bytes of an image. I am using Mobile Imaging SDK and I am developing in eMbedded Visual C++ 4.0 for PocketPC.How can I do it? Is there any function?

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 : Friday, September 28, 2007 8:53:39 AM(UTC)

BoydP  
Guest

Groups: Guests
Posts: 3,022

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

You can use the GetRow method exposed through the IRasterImage interface.  Please refer to the documentation on this method.  If you have any specific questions or problems with this method please do not hesitate to ask.
 
#3 Posted : Monday, October 1, 2007 1:49:36 AM(UTC)

sara  
sara

Groups: Registered
Posts: 19



Hello,

First of all, thanks for your fast answer. This is my first time programming for mobile devices and I am quite confused.
I am running the maindemo example (Example\WinCE\PocketPC) in visual embedded 4.0 and I need the array of bytes of an image in this context. In this example the image is stored as a bitmap and I do not know how to transform it into the IRasterImage that you have mentioned. I look for the IRasterImage interface and it is defined inside "Leadtools.CF.dll". But this dll is for .net, isn't it? and I am developing using C++. If it is necessary to add it to the project can you tell me please how to do it and how to use it.
I would be very grateful if you could tell me how to get the array of bytes in the code of the maindemo example because I need some functions used there. Well, I need to read an image from a file and get its array of bytes in order to transform it later.
I hope you can help me because I need to do it for next week work meeting.
 
#4 Posted : Monday, October 1, 2007 5:35:53 AM(UTC)

BoydP  
Guest

Groups: Guests
Posts: 3,022

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

Sorry I overlooked that you were using C++.  I am unsure what you are trying to do here.  If you read an image from a file you will have all of its information stored in the BITMAPHANDLE object that you pass to L_LoadBitmap(...).  If you need to get the actual data of the bitmap to do some kind of custom processing the you can call L_GetBitmapRow(...) for each row to get the entire contents of the bitmap.  When you say "how to get the array of bytes in the code of the maindemo example because I need some functions used there", what functions are you referring to?  Also, when you say array of bytes do you mean the BITMAPHANDLE or the actual data of the bitmap?
 
#5 Posted : Monday, October 8, 2007 6:18:11 AM(UTC)

sara  
sara

Groups: Registered
Posts: 19



Hello, sorry for no answering earlier. I was out last week. Well, I have tried to use the L_GetBitmapRow() function but there is any place where I can find what each parameter means and what functions are available. I mean, there is any help about the functions in the library.
I need the array of bytes that define the image in order to study the colors in the image and make some transformations. I do not know the difference between the array of bytes of the BITMAPHANDLE or the bitmap, acn you please explain me.
Thank you very muhc for your help.

By the way, I would like to know if the Gabor filters can be used. I saw that you work with Sobel filters
 
#6 Posted : Monday, October 8, 2007 6:42:48 AM(UTC)

BoydP  
Guest

Groups: Guests
Posts: 3,022

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

There is a help file which documents every function available in the Mobile Imaging SDK.  Under the start menu go to LEADTOOLS Mobile Imaging->LEADTOOLS Raster API Documentation.  If you can't find it there, under your LEADTOOLS install directory go to the Help folder and open ltdlln.chm.  This is the API help file. 

The BITMAPHANDLE is used by all LEADTOOLS functions to load, save, display, etc. images.  You can get the actual image data of this BITMAPHANDLE through the L_GetBitmapRow() functiona and you can set the data using the L_PutBitmapRow().  Please look through the documentation for information on those functions.  There are multiple code samples which show you how to use them in the help file. 

I have also attached a demo project which shows you how to use them.
File Attachment(s):
GETROW.zip (11kb) downloaded 23 time(s).
 
#7 Posted : Wednesday, October 10, 2007 4:42:03 AM(UTC)

sara  
sara

Groups: Registered
Posts: 19



Thank you very much. I am now loooking at the documentation and the example.
 
#8 Posted : Wednesday, October 17, 2007 4:32:27 AM(UTC)

sara  
sara

Groups: Registered
Posts: 19


Hello, your example is very useful but I have still two problems.
The first one is that I get the array of bytes of an image an then after transforming it I can not display the new image. The initial image has 24bits/pixel and after the transformation it has 8bits/pixel, is it a problem? I have attached the code, so that you could easily see the mistake.
Secondly, the implemantation is in C but I would like to take advantage of the code of the PC application that I have. How can I do it? I have work always in C++ and I do not know if it is possible. Can you help me?
 
#9 Posted : Wednesday, October 17, 2007 4:35:10 AM(UTC)

sara  
sara

Groups: Registered
Posts: 19


I can not attach the file.
 
#10 Posted : Wednesday, October 17, 2007 4:36:47 AM(UTC)

sara  
sara

Groups: Registered
Posts: 19


Here is the code:
/* Allocate and lock the buffer */
hBuf = GlobalAlloc(GMEM_MOVEABLE,Data.BitmapHandle.BytesPerLine);
pBuf = (L_UCHAR L_FAR *)GlobalLock( hBuf );
/* Allocate and lock the buffer 2*/
hBuf2= GlobalAlloc(GMEM_MOVEABLE,(Data.BitmapHandle.BytesPerLine)*Data.BitmapHandle.Height);
pBuf2 = (L_UCHAR L_FAR *)GlobalLock( hBuf2 );
/* Allocate and lock the buffer 3*/
hBuf4=GlobalAlloc(GMEM_MOVEABLE,(Data.BitmapHandle.Width)*Data.BitmapHandle.Height);
imagen_array = (L_UCHAR L_FAR *)GlobalLock( hBuf4 );

// Get the array of bytes of the whole image (stored in pBuf2)
for(nRow = 0; nRow < Data.BitmapHandle.Height; nRow++)
{
L_GetBitmapRow(&Data.BitmapHandle, pBuf, nRow, Data.BitmapHandle.BytesPerLine);

for(uByte = 0; uByte < Data.BitmapHandle.BytesPerLine; uByte++)
pBuf2[(nRow*Data.BitmapHandle.BytesPerLine)+uByte] = pBuf[uByte]
}

// Transform the image and store the new array of bytes in “imagen_array”
…………………………………………..
// Try to display "imagen_array"
// Initialize the new BitmapHandle with 8Bits/pixel
L_InitBitmap(&NewBitmap,sizeof(BITMAPHANDLE),Data.BitmapHandle.Width,
Data.BitmapHandle.Height,8);
// Copy the palette to the new bitmap, is it necessary ???????
L_CopyBitmapPalette(&NewBitmap,&Data.BitmapHandle);
// Allocate the storage to hold the image data
L_AllocateBitmap(&NewBitmap,TYPE_CONV);
// Free the old bitmap
L_FreeBitmap(&Data.BitmapHandle);
// Make the Data.BitmapHandle point to the new image data
L_CopyBitmapHandle(&Data.BitmapHandle,&NewBitmap,sizeof(BITMAPHANDLE));


/* Allocate and lock the buffer */
hBuf_aux = GlobalAlloc(GMEM_MOVEABLE,Data.BitmapHandle.BytesPerLine);
pBuf_aux = (L_UCHAR L_FAR *)GlobalLock( hBuf_aux );

// Get the information for each row
for(nRow = 0; nRow < Data.BitmapHandle.Height; nRow++)
{
for(uByte = 0; uByte < Data.BitmapHandle.BytesPerLine; uByte++)
{
pBuf_aux[uByte]=imagen_array[(nRow*Data.BitmapHandle.BytesPerLine)+uByte];
}
L_PutBitmapRow(&Data.BitmapHandle, pBuf_aux, nRow, Data.BitmapHandle.BytesPerLine);
}

/* Free memory that we no longer need */
GlobalUnlock(hBuf);
GlobalFree(hBuf);
GlobalUnlock(hBuf2);
GlobalFree(hBuf2);
GlobalUnlock(hBuf4);
GlobalFree(hBuf4);
 
#11 Posted : Thursday, October 18, 2007 12:29:49 PM(UTC)

BoydP  
Guest

Groups: Guests
Posts: 3,022

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

Are you simply trying to convert the image from 24-bits per pixel to 8-bits per pixel?
 
#12 Posted : Thursday, October 18, 2007 9:05:54 PM(UTC)

sara  
sara

Groups: Registered
Posts: 19



No, I have an initial image with 24-bits per pixel. I get the array of bytes of this image and I have a process to transform the image into a "special" grayscale image, taking into acount some relevants parts of the image in order to invert or not the colors. Thus, after the transformation I have a new array of bytes of an image with 8-bits per pixel and when I try to display it I get a whole black image, but the information in my new array is different from black color. So I do not know if I have something missing.

I initialize a new BitmapHandle with 8-bits per pixel and replace it in "Data" structure. Then I put the rows (from the new array) into the Bitmaphandle. You have the whole code in a previous post. So my problem could be how to display the new image whose number of bits per pixel has changed.
 
#13 Posted : Tuesday, November 13, 2007 5:44:34 PM(UTC)

phuong  
phuong

Groups: Registered
Posts: 1


Hi friend,
i can't download your zip file, please help me, really i very need an example about "How can i get the array of byte of an image"
thanks so much.
 
#14 Posted : Wednesday, November 14, 2007 7:19:27 AM(UTC)

BoydP  
Guest

Groups: Guests
Posts: 3,022

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

sara,

If you want to convert the image from 24-bits to 8-bits then you must define your own palette otherwise the bitmap will not be displayed properly.  Since your image is appearing as black, then you must be doing something wrong along the way in processing the pixel data.  Here is an example which loads a 24-bit image and then uses L_GetBitmapRow to get all of the pixel data and then it fills in a new bitmap of the same dimensions.  The effect is that the image appears to be 33% of its original size because the pixel data is not being transformed it is simply being put in to the new bitmap byte by byte. 

    L_INT nRet;
    L_UCHAR L_FAR *pBuf, *pBuf2, *pBuf3;
    HGLOBAL hBuf, hBuf2, hBuf3;
    BITMAPHANDLE newBitmap;
    L_InitBitmap(&newBitmap, sizeof(BITMAPHANDLE), bitmap.Width, bitmap.Height, bitsPerPixel);

    L_CopyBitmapPalette(&newBitmap, &bitmap);

    L_AllocateBitmap(&newBitmap, TYPE_CONV);

    L_AccessBitmap(&newBitmap);
    L_AccessBitmap(&bitmap);

    hBuf = GlobalAlloc(GMEM_MOVEABLE, bitmap.BytesPerLine);
    pBuf = (L_UCHAR L_FAR *)GlobalLock(hBuf);

    hBuf2 = GlobalAlloc(GMEM_MOVEABLE, bitmap.BytesPerLine * bitmap.Height);
    pBuf2 = (L_UCHAR L_FAR *)GlobalLock(hBuf2);

    hBuf3 = GlobalAlloc(GMEM_MOVEABLE, newBitmap.BytesPerLine);
    pBuf3 = (L_UCHAR L_FAR *)GlobalLock(hBuf3);

    for(L_INT nRow = 0; nRow<bitmap.Height; nRow++)
    {
        nRet = L_GetBitmapRow(&bitmap, pBuf, (bitmap.Height-1) - nRow, numbBytes);
        if(nRet != numbBytes)
        {
            MessageBox(TEXT("Error getting data"));
            return;
        }

        for(L_UINT uByte = 0; uByte < bitmap.BytesPerLine; uByte++)
        {
            pBuf2[(nRow * bitmap.BytesPerLine) + uByte] = pBuf[uByte];
        }
    }

    for(L_INT nRow = 0; nRow<newBitmap.Height; nRow++)
    {
        for(L_UINT uByte = 0; uByte < newBitmap.BytesPerLine; uByte++)
        {
            pBuf3[uByte] = pBuf2[(nRow * bitmap.BytesPerLine) + uByte];
        }

        nRet = L_PutBitmapRow(&newBitmap, pBuf3, nRow, newBitmap.BytesPerLine);
        if(nRet != newBitmap.BytesPerLine)
        {
            MessageBox(TEXT("Error putting data"));
            return;
        }
    }

    L_ReleaseBitmap(&newBitmap);
    L_ReleaseBitmap(&bitmap);

    L_FreeBitmap(&bitmap);

    L_CopyBitmapHandle(&bitmap, &newBitmap, sizeof(BITMAPHANDLE));

    GlobalUnlock(hBuf);
    GlobalFree(hBuf);
    GlobalUnlock(hBuf2);
    GlobalFree(hBuf2);
    GlobalUnlock(hBuf3);
    GlobalFree(hBuf3);
 
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.162 seconds.