×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    338

    Could not use SetPixel() of TBitmapUtil properly

    hi,
    I tried to convert a gray-scale bitmap to black-and-white bitmap. For that purpose i tried with the following code.
    Code:
    void CUDP_ConnAppView::FilterBitmap()
    	{
    	TBitmapUtil bUtil(bitmap);
    	TRgb rgbVal;
    	bUtil.Begin(TPoint(0,0));
    	int h = bitmap->SizeInPixels().iHeight;
    	int w = bitmap->SizeInPixels().iWidth;
    	for(int r = 0; r < h; r++)
    		{
    		for(int c = 0; c < w; c++)
    			{
    			TPoint p = TPoint(c, r);
    			bitmap->GetPixel(rgbVal, p);
    			if(rgbVal.Gray256() > 155)
    				{
    				bUtil.SetPixel(TUint32(0xff));
    				}
    			else
    				{
    				bUtil.SetPixel(TUint32(0x00));
    				}
    			bUtil.IncXPos();
    			}
    		bUtil.IncYPos();
    		}	
    	bUtil.End();
    	}
    I expected that the reformed bitmap has been changed. But I failed. I knew and i debugged that the grayscale bitmap has 8bpp. i loaded the image using EGray256 displaymode. You can see that the changed bitmap is actually remaining Gray256 (though it should show only b&w i.e 255 and 0). If it is, then it is okay for me. If i can compress to only one bit per pixel then it is even better. Do you have any suggestion ? For your kind information, when loading the bitmap I can't use EGray2 because it does halftoning, which i don't want. So I am loading with EGray256 and changing it to b&w by myself.

  2. #2
    Registered User
    Join Date
    Feb 2011
    Posts
    338

    Re: Could not use SetPixel() of TBitmapUtil properly

    I got the solution. the code will be like this
    Code:
    void CUDP_ConnAppView::FilterBitmap()
    	{
    	TBitmapUtil bUtil(bitmap);
    	TRgb rgbVal;
    	bUtil.Begin(TPoint(0,0));
    	int h = bitmap->SizeInPixels().iHeight;
    	int w = bitmap->SizeInPixels().iWidth;
    	for(int r = 0; r < w; r++)
    		{
    		for(int c = 0; c < h; c++)
    			{
    			
    			if(bUtit.GetPixel() > 155)
    				{
    				bUtil.SetPixel(TUint32(0xff));
    				}
    			else
    				{
    				bUtil.SetPixel(TUint32(0x00));
    				}
    			bUtil.IncXPos();
    			}
    		bUtil.IncYPos();
    		}	
    	bUtil.End();
    	}
    in the code the sequence in for-loop is changed and the GetPixel() of TBitmapUtil is used.
    Last edited by wizard_hu_; 2012-06-27 at 13:40. Reason: fixed [\CODE] to [/CODE]

Similar Threads

  1. TBitmapUtil can not modify a bmp
    By ptclin_2007 in forum Symbian
    Replies: 2
    Last Post: 2010-11-18, 16:09
  2. TBitmapUtil vs TDisplayMode
    By bart12 in forum Symbian Media (Closed)
    Replies: 2
    Last Post: 2009-07-11, 13:49
  3. Is there a 'setpixel' for image objects?
    By savago in forum Symbian
    Replies: 3
    Last Post: 2007-08-26, 20:45
  4. SetPixel without TBitmapUtils
    By manu.20 in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2005-05-23, 13:50
  5. offscreen bitmap setpixel
    By eduardoabinader in forum Symbian User Interface
    Replies: 0
    Last Post: 2004-04-22, 14:41

Posting Permissions

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