×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    34

    Not able to create mask for the image

    Hi All,
    I am developing an application where i need to create the mask of the original image.
    My image is just blue(filled)square surrounded by magenta color.
    Now i want to create mask of this image which should be that blue square has to be white and rest should be black.
    here is my code.


    RFs session;
    session.Connect();
    _LIT(KImageFile,"c:\\sample.bmp");

    iDecoder= CImageDecoder::FileNewL(session,KImageFile,CImageDecoder::EAllowGeneratedMask,KNullUid,KNullUid,KNullUid);
    session.Close();
    //Get the image attributes
    TFrameInfo FrameInfo = iDecoder->FrameInfo(0);

    Image->Create(FrameInfo.iOverallSizeInPixels,FrameInfo.iFrameDisplayMode );
    Imagemask->Create(FrameInfo.iOverallSizeInPixels,EGray256);
    //TRequestStatus Status = KRequestPending;
    iStatus=KRequestPending;
    //Decode the bitmap from the file to symbian type bitmap
    iDecoder->Convert(&iStatus,*Image,*Imagemask,0);
    if(!IsActive())
    SetActive();


    After this i am not getting a proper mask.
    so if i bitblt my image using bitbltmasked..i get same image displayed.
    and if i bitblt only mask...only white background i can see.

    please tell me the problem with my code.

  2. #2
    Nokia Developer Champion
    Join Date
    Jan 2008
    Location
    Moscow, Russia
    Posts
    3,348

    Re: Not able to create mask for the image

    See this article - How to read images to Symbian bitmap

    And try to replace
    Code:
    RFs session;
    session.Connect();
    iDecoder= CImageDecoder::FileNewL(session,KImageFile,CImageDecoder::EAllowGeneratedMask,KNullUid,KNullUid,KNullUid);
    session.Close();
    with
    Code:
    ...
    {
     TBuf8<255> ImageType;
     GetFileType(KImageFile, ImageType);
    
     iDecoder = CImageDecoder::FileNewL(CCoeEnv::Static()->FsSession(),KImageFile,ImageType);
     ...
     ...
     ...
    }
    
    void C***::GetFileType(const TDesC& aFileName, TDes8& aFileType)
    {
    	TEntry FileEntry;
     
    	if(CCoeEnv::Static()->FsSession().Entry(aFileName,FileEntry) == KErrNone)
    	{
    		TBuf8<255> FileBuffer;
    		
    		if(!FileEntry.IsDir())
    		{
    			TInt FileSize = FileEntry.iSize;
     
    			if(FileSize > 255)
    			{
    				FileSize = 255;
    			}
    			
    			if(CCoeEnv::Static()->FsSession().ReadFileSection(aFileName,0,FileBuffer,FileSize) == KErrNone)
    			{
    				RApaLsSession RSession;
    				if(RSession.Connect() == KErrNone)
    				{	
    					TDataRecognitionResult FileDataType;
     
    					RSession.RecognizeData(aFileName,FileBuffer,*&FileDataType);
    					
    					if(FileDataType.iConfidence > aResult.iConfidence)
    					{
    						aFileType.Copy(FileDataType.iDataType.Des8());
    					}
    					
    					RSession.Close();
    				}
    			}
    		}
    	}
    }

  3. #3
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: Not able to create mask for the image

    .bmp file format does not support "contained" mask, that is why CImageDecoder does not decode a mask for you. If you decide that magenta color indicates transparent pixels, that is your personal decision, obviously not part of the file format itself.
    So you have to create the mask for yourself, TBitmapUtil can help you in doing that, it enables you to read pixels from the image, then compare the color to your color key, and write a black/white pixel to the mask accordingly.

  4. #4
    Registered User
    Join Date
    Nov 2008
    Posts
    34

    Re: Not able to create mask for the image

    Thanks Wizard_hu!!

    But creating a mask using TBitmapUtil is a very slow process as you have to compare each pixel. so on device it is going to take lots of time. we can create the mask for .png if it contains alphs bending information.
    So do i have to change all my .bmp to .png format?

  5. #5
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: Not able to create mask for the image

    Quote Originally Posted by amey_kulkarni View Post
    Thanks Wizard_hu!!

    But creating a mask using TBitmapUtil is a very slow process as you have to compare each pixel. so on device it is going to take lots of time. we can create the mask for .png if it contains alphs bending information.
    So do i have to change all my .bmp to .png format?
    why not change all images to MBM format where you package both image and it's mask.

  6. #6
    Registered User
    Join Date
    Nov 2008
    Posts
    34

    Re: Not able to create mask for the image

    I can not change images to mbm format. Because application takes dynamic calls so depending on this you need to decode the image and display it on the screen.There are number of images so not feasible to create mbm.

  7. #7
    Super Contributor
    Join Date
    Jul 2008
    Location
    Chennai,India
    Posts
    889

    Re: Not able to create mask for the image

    I can not change images to mbm format. Because application takes dynamic calls so depending on this you need to decode the image and display it on the screen.There are number of images so not feasible to create mbm.
    There is no other go.. you have to convert the images to .mbm for display....
    May be You cud better go for decoding of .png files instead of .bmp files...
    I am using/decoding .png files at run-time along with the mask and it's not too long.
    Also .png's consume less space than .bmp...

  8. #8
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: Not able to create mask for the image

    I do not see the problem. If you have access to the original images (so you are do not downloading them in runtime for example), it is pretty straightforward to convert them to .mbm. Also note that a .mbm file can contain a significant number of bitmaps (just search for avkon.mbm with Google for a "famous" example). And .mbm is a lossless compressed format actually.
    Check how Graphics example works (part of all S60 1st and 2nd edition SDK-s as S[eries]60Ex\Graphics, and re-introduced in S60 3rd edition FP1 - somewhere in S60Ex or S60CppExamples). And there is a downloadable example too, Docs above, Symbian C++, Graphics, Scalable Screen Drawing (or something like that).

  9. #9
    Registered User
    Join Date
    Nov 2008
    Posts
    34

    Re: Not able to create mask for the image

    Thanks, Wizard_Hu_.
    I am just porting the code which was developed such that for displaying image it takes the local path of iamge on device and decodes it and displays it. So i dont have access to change the behaviour of this code so i have no alternative except using decoder and thats where it is creating the problem of mask.
    So my original images should contain the information so that i can create the mask successfully.

    But still thanks friends for the guidance.

Similar Threads

  1. How to create mask for bmp files??
    By rohanwaugh in forum Symbian User Interface
    Replies: 8
    Last Post: 2008-12-03, 05:18
  2. how to create a mask of image dynamically
    By raysky in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2008-11-03, 05:43
  3. Can we Create run time image in flash lite 2.0?
    By sachupadhye@gmail.com in forum [Archived] Flash Lite on Nokia Devices
    Replies: 3
    Last Post: 2008-07-09, 10:12
  4. how to create Image from Graphics
    By afka in forum Mobile Java General
    Replies: 1
    Last Post: 2006-09-03, 01:29
  5. How to create an empty transparant image?
    By calleandersson in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2004-12-29, 15:55

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×