×

Discussion Board

Results 1 to 12 of 12
  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    15

    Unhappy How can I reverse the color in the screen?

    How can I reverse the color in the screen?

    I mean ,I got a large bitmap and drawed it to the screen ,and then ,I wanted to reverse part of it's color. How can I do that?

    I have searched the sdk,but nothing can help me,and there is seldom comments on the internet.

    help!


    Appreciate you help. Thanks.

    sanmu163

  2. #2
    Registered User
    Join Date
    Jan 2006
    Posts
    279

    Smile Re: How can I reverse the color in the screen?

    I am afraid you should do it manually with TBitmapUtil

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    15

    Unhappy Re: How can I reverse the color in the screen?

    Thank you for your reply.
    Yes,I have read many articles,and I decide to change it in pixel by myself, but now ,I have encounter a new problem.Here is the code:

    CWsBitmap* iNBT_normal;
    iNBT_normal = iEikonEnv->CreateBitmapL(bmPath, *(pActiveButton->pactivebmpid));

    TBitmapUtil bitmapUtil(iNBT_normal);
    if ( iNBT_normal->IsLargeBitmap() )
    {
    bitmapUtil.Begin(TPoint(0,0));
    }
    TInt djsXPos = 1;
    TInt djsYPos = 1;
    TSize inSize = iNBT_normal->SizeInPixels();
    for (; djsYPos < 10; djsYPos++)
    {
    bitmapUtil.SetPos(TPoint(1,djsYPos));//here it's OK
    for (djsXPos = 1; djsXPos < 20; djsXPos++)
    {
    TUint32 iPixel = bitmapUtil.GetPixel();
    bitmapUtil.SetPixel(iPixel);
    bitmapUtil.IncXPos();
    }
    }
    if ( iNBT_normal->IsLargeBitmap() )
    {
    bitmapUtil.End();
    }

    It crash in TUint32 iPixel = bitmapUtil.GetPixel();
    or(is there is no the upper statement) bitmapUtil.SetPixel(iPixel);

    the comment I get from the IDE is : Access Violation at address 0x41409C06;

    Waiting for you help,Thank you .

  4. #4
    Registered User
    Join Date
    Jan 2006
    Posts
    279

    Re: How can I reverse the color in the screen?

    I have used TBitmapUtil only with CFbsBitmap*, but I guess it should work with CWsBitmap also.

    1. Is your bitmapUtil->Begin(TPoint(0, 0)) always called, it should always be.
    2. what is the value of inSize, because if it is a vector bitmap you should call SetSize before that
    If nothing helps, please take a look at my code, it has been tested on 3rd edition, but will work on 2nd too
    Code:
    CFbsBitmap* CTitleManager::CreateNewBitmapL(CFbsBitmap* aSrcBitmap)
    {
    	TSize bitmapSize = aSrcBitmap->SizeInPixels();
    	CFbsBitmap*	newBitmap = new(ELeave) CFbsBitmap();
    	CleanupStack::PushL(newBitmap);//+bitmap
    	newBitmap->Create(bitmapSize, aSrcBitmap->DisplayMode());
    
    	TBitmapUtil bitmapUtil1(aSrcBitmap);
    	bitmapUtil1.Begin(TPoint(0, 0));
    	TBitmapUtil bitmapUtil2(newBitmap);
    	bitmapUtil2.Begin(TPoint(0, 0));
    
    	for (TInt y = 0; y < bitmapSize.iHeight;y++)
    	{
    		for (TInt x = 0; x < bitmapSize.iWidth; ++x)
    		{
    			bitmapUtil1.SetPos(TPoint(x, y));
    			TInt col = bitmapUtil1.GetPixel();
    			bitmapUtil2.SetPos(TPoint(x, y));
    			bitmapUtil2.SetPixel(col);
    		}
    	}
    	bitmapUtil2.End();
    	bitmapUtil1.End();
    	CleanupStack::Pop();//newBitmap
    	return newBitmap;
    }

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    15

    Unhappy Re: How can I reverse the color in the screen?

    Thank you ,Microsoft2.

    I'm sorry ,I can't see much different in your codes,but thank you all the same,

    I want to tell you something mort precisely.

    1,When it crash in GetPixel(),it doesn't call bitmapUtil->Begin(TPoint(0, 0)) ;But when I remove the if statements,that is say,I call bitmapUtil->Begin(TPoint(0, 0)) all the time, it crash in bitmapUtil->Begin(TPoint(0, 0)) ,not GetPixel().

    2,The value of inSize is (42,20),

    I will take a deep look in your code now,appreciate to your help.


    sanmu163

  6. #6
    Registered User
    Join Date
    Jan 2006
    Posts
    279

    Re: How can I reverse the color in the screen?

    Why not try CFbsBitmap::Load:
    Code:
    CFbsBitmap* iNBT_normal = new (ELeave) CFbsBitmap();
    iNBT_normal->Load(bmPath, *(pActiveButton->pactivebmpid), EFalse);
    I don't see what else could be the problem ...

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    15

    Unhappy Re: How can I reverse the color in the screen?

    I have try this load() method,but unfortunatly,The crash remains.

    this code:
    iNBT_normal->Load(bmPath, *(pActiveButton->pactivebmpid), EFalse);

    is sucess(return 0),and the
    bitmapUtil.Begin(TPoint(0,0));
    crashs.

    But When I creat a new bitmap like this ,
    CFbsBitmap* iNBT_normal2 = new (ELeave) CFbsBitmap();
    TInt err2 = iNBT_normal2->Create( inSize, EColor4K);

    then ,the bitmapUtil.Begin(TPoint(0,0));
    is run secessfully.

    Thank you for your help.Microsoft2.

    Sanmu163.

  8. #8
    Registered User
    Join Date
    Apr 2006
    Posts
    15

    Unhappy Re: How can I reverse the color in the screen?

    Microsoft2, I have something new to want you to kneow.

    If I use TInt err2 = iNBT_normal2->Create( inSize, EColor16M);
    it crashes like the original one.
    and I have try TInt err2 = iNBT_normal2->Create( inSize, iNBT_normal->DisplayMode()); just like your code,I crashes all the same.

    So I guss it's the problem of the playableMode.

    Am i right? Can you give me some advice?

    Thank you .


    Sanmu163.

  9. #9
    Registered User
    Join Date
    Apr 2006
    Posts
    15

    Re: How can I reverse the color in the screen?

    I have just see that my bitmap's displayableMode is EColor16M.

    This maybe the problem.Can I change it in the program or just the Resource?

    Does here any solution?

    Appreciate your reply.Thank you!


    Sanmu163.

  10. #10
    Registered User
    Join Date
    Jan 2006
    Posts
    279

    Re: How can I reverse the color in the screen?

    May be this is really the problem, but I am not sure if I can help you in the best way, if someone else knows more please advice!
    In 3rd edition I am using
    AknIconUtils::CreateIconL(bitmap, bitmapMask, KMbmFileName, aBitmapId, aBitmapMaskId)
    to create bitmaps and in previous SDKs I am using BitmapMethods from Nokia examples:
    C:\Symbian\7.0s\Series60_v21_CW\Series60Ex\helperfunctions\bitmapmethods.cpp
    Here is the code if you don't have 21
    Code:
    // Copyright (c) 2000, Nokia. All rights reserved.
    
    #include "bitmapmethods.h"
    #include <eikenv.h>
    #include <fbs.h>
    
    
    CFbsBitGc* NBitmapMethods::CreateGraphicsContextLC(CFbsBitmapDevice& aBitmapDevice)
    	{
    	CFbsBitGc* graphicsContext = NULL;
    	User::LeaveIfError(aBitmapDevice.CreateContext(graphicsContext));
    	CleanupStack::PushL(graphicsContext);
    	return graphicsContext;
    	}
    
    
    CFbsBitGc* NBitmapMethods::CreateGraphicsContextL(CFbsBitmapDevice& aBitmapDevice)
    	{
    	CFbsBitGc* gc = CreateGraphicsContextLC(aBitmapDevice);
    	CleanupStack::Pop(gc);
    	return gc;
    	}
    
    
    CFbsBitmapDevice* NBitmapMethods::CreateBitmapDeviceLC(CFbsBitmap& aBitmap)
    	{
    	CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(&aBitmap);
    	CleanupStack::PushL(bitmapDevice);
    	return bitmapDevice;
    	}
    
    
    CFbsBitmapDevice* NBitmapMethods::CreateBitmapDeviceL(CFbsBitmap& aBitmap)
    	{
    	CFbsBitmapDevice* device = CreateBitmapDeviceLC(aBitmap);
    	CleanupStack::Pop(device);
    	return device;
    	}
    
    
    CFbsBitmap* NBitmapMethods::CreateBitmapLC(TSize aSizeInPixels,TDisplayMode aDispMode)
    	{
    	CFbsBitmap* bitmap = new(ELeave) CFbsBitmap();
    	CleanupStack::PushL(bitmap);
    	User::LeaveIfError(bitmap->Create(aSizeInPixels,aDispMode));
    	ASSERT((bitmap->DisplayMode() == KColourDepth) || (bitmap->DisplayMode()  == EGray2));
    	return bitmap;
    	}
    
    
    CFbsBitmap* NBitmapMethods::CreateBitmapL(TSize aSizeInPixels,TDisplayMode aDispMode)
    	{
    	CFbsBitmap* bitmap = CreateBitmapLC(aSizeInPixels,aDispMode);
    	CleanupStack::Pop(bitmap);
    	return bitmap;
    	}
    
    
    CFbsBitmap* NBitmapMethods::CreateBitmapLC(const TDesC& aFileName,TInt aId)
    	{
    	CFbsBitmap* bitmap = new(ELeave) CFbsBitmap();
    
    	CleanupStack::PushL(bitmap);
    	TInt loadException = bitmap->Load(aFileName,aId);
    	User::LeaveIfError(loadException);
    
    	if ((bitmap->DisplayMode() == KColourDepth) || (bitmap->DisplayMode()  == EGray2))
    		{
    		return bitmap;
    		}
    	else
    		{
    		CFbsBitmap* newBitmap = CreateBitmapLC(	bitmap->SizeInPixels(),KColourDepth);															
    
    		CFbsBitmapDevice*		bitmapDevice	= CreateBitmapDeviceLC(*newBitmap);
    		CFbsBitGc*				bitmapGc		= CreateGraphicsContextLC(*bitmapDevice);
    		bitmapGc->BitBlt(TPoint(0,0),bitmap,TRect(bitmap->SizeInPixels()));
    		CleanupStack::PopAndDestroy(2); // gc and device
    		// The next three lines are here to get rid of the old bitmap but keep the new one 
    		CleanupStack::Pop(newBitmap);
    		CleanupStack::PopAndDestroy(bitmap);
    		CleanupStack::PushL(newBitmap);
    
    		return newBitmap;
    		}
    	}
    
    
    CFbsBitmap* NBitmapMethods::CreateBitmapL(const TDesC& aFileName,TInt aId)
    	{
    	CFbsBitmap* bitmap = CreateBitmapLC(aFileName, aId);
    	CleanupStack::Pop(bitmap);
    	return bitmap;
    	}
    
    void NBitmapMethods::BitBltMaskedEntireBitmap(CFbsBitGc& aTargetGc,TPoint aTopLeft,
    											  const CFbsBitmap& aBitmap,const CFbsBitmap& aBitMask)
    	{
    	PartialReset(aTargetGc);
    	aTargetGc.BitBltMasked(aTopLeft,&aBitmap,aBitmap.SizeInPixels(),&aBitMask,ETrue);
    	PartialReset(aTargetGc);
    	}
    
    
    void NBitmapMethods::PartialReset(CFbsBitGc& aGc)
    	{
    	aGc.SetPenSize(TSize(1,1));
    	aGc.SetPenColor(KRgbBlack);
    	aGc.SetPenStyle(CFbsBitGc::ESolidPen);
    	aGc.SetDrawMode(CFbsBitGc::EDrawModePEN);
    	aGc.DiscardFont();
    	aGc.DiscardBrushPattern();
    	aGc.SetBrushColor(KRgbWhite);
    	aGc.SetBrushStyle(CFbsBitGc::ENullBrush);
    	aGc.SetCharJustification(0,0);
    	aGc.SetWordJustification(0,0);
    	aGc.SetDitherOrigin(TPoint(0,0));
    	aGc.SetPenStyle(CFbsBitGc::ENullPen);
    	aGc.SetShadowMode(EFalse);
    	aGc.SetStrikethroughStyle(EStrikethroughOff);
    	aGc.SetUnderlineStyle(EUnderlineOff);
    	aGc.SetUserDisplayMode(ENone);
    	}
    h file
    Code:
    /* Copyright (c) 2001, Nokia. All rights reserved */
    
    #ifndef __BITMAPMETHODS__
    #define __BITMAPMETHODS__
    
    #define KColourDepth EColor4K
    
    //Ensure these libraries are linked against:
    //LIBRARY           bitgdi.lib
    
    
    #include <e32base.h>
    #include <gdi.h>
    
    class CFbsBitGc;
    class CFbsBitmapDevice;
    class CWsBitmap;
    class CFbsBitmap;
    
    
    /*! 
      @namespace NBitmapMethods
      
      @discussion A set of functions to make bitmap manipulation easier
      */
    namespace NBitmapMethods
    {
    /*!
      @function CreateGraphicsContextLC
      
      @discussion Create a graphics context and leave it on the cleanup stack
      @param aBitmapDevice a reference to a bitmap device
      */
    	CFbsBitGc* CreateGraphicsContextLC(CFbsBitmapDevice& aBitmapDevice);
    
    /*!
      @function CreateGraphicsContextL
      
      @discussion Create a graphics context
      @param aBitmapDevice a reference to a bitmap device
      */
    	CFbsBitGc* CreateGraphicsContextL(CFbsBitmapDevice& aBitmapDevice);
    
    /*!
      @function CreateBitmapDeviceLC
      
      @discussion Create a bitmap device and leave it on the cleanup stack
      @param aBitmap a reference to a bitmap
      */
    	CFbsBitmapDevice* CreateBitmapDeviceLC(CFbsBitmap& aBitmap);
    
    /*!
      @function CreateBitmapDeviceL
      
      @discussion Create a bitmap device
      @param aBitmap a reference to a bitmap
      */
    	CFbsBitmapDevice* CreateBitmapDeviceL(CFbsBitmap& aBitmap);
    
    /*!
      @function CreateBitmapLC
      
      @discussion Create a bitmap and leave it on the cleanup stack
      @param aSizeInPixels the size of the bitmap to be created
      @param aDispMode the display mode of the bitmap
      */
    	CFbsBitmap* CreateBitmapLC(TSize aSizeInPixels,TDisplayMode aDispMode);
    
    /*!
      @function CreateBitmapL
      
      @discussion Create a bitmap
      @param aSizeInPixels the size of the bitmap to be created
      @param aDispMode the display mode of the bitmap
      */
    	CFbsBitmap* CreateBitmapL(TSize aSizeInPixels,TDisplayMode aDispMode);
    
    /*!
      @function CreateBitmapLC
      
      @discussion Create a bitmap from an mbm file bitmap and leave it on the cleanup stack
      @param aFileName the name of an mbm file
      @param aId the position of the bitmap in the mbm file
      */
    	CFbsBitmap* CreateBitmapLC(const TDesC& aFileName,TInt aId);
    
    /*!
      @function CreateBitmapLC
      
      @discussion Create a bitmap from an mbm file bitmap
      @param aFileName the name of an mbm file
      @param aId the position of the bitmap in the mbm file
      */
    	CFbsBitmap* CreateBitmapL(const TDesC& aFileName,TInt aId);
    
    /*!
      @function BitBltMaskedEntireBitmap
      
      @discussion Blit the entire of a bitmap with a mask onto a gc
      @param aTargetGc gc to blit onto
      @param aTopLeft the position at which the top left of the bitmap will be placed on the gc
      @param aBitmap the bitmap to blit
      @param aBitMask the mask
      */
    	void BitBltMaskedEntireBitmap(CFbsBitGc& aTargetGc,TPoint aTopLeft,const CFbsBitmap& aBitmap,
    								const CFbsBitmap& aBitMask);
    /*!
      @function PartialReset
      
      @discussion Reset a gc so that it is in a sensible state.
      Not all settings are reset, just some of the more useful ones
      @param aGc the gc to reset
      */
    	void PartialReset(CFbsBitGc& aGc);
    }
    
    #endif //__BITMAPMETHODS__
    and then I create the bitmap using
    Code:
    bitmap = NBitmapMethods::CreateBitmapL(AbsPath(KMbmFileName), EMbmBrightMoon);

  11. #11
    Registered User
    Join Date
    May 2005
    Location
    Indonesia
    Posts
    198

    Re: How can I reverse the color in the screen?

    Try this, it will inverse the color on the screen. Put it in your Draw() function.

    CWindowGc& gc = SystemGc();
    ...
    ...
    gc.SetDrawMode( CWindowGc::EDrawModeXOR );
    gc.SetPenStyle( CWindowGc::ENullPen );
    gc.SetBrushStyle( CWindowGc::ESolidBrush );
    gc.SetBrushColor( KRgbWhite );
    gc.DrawRect( Rect() );

    good luck

  12. #12
    Registered User
    Join Date
    Apr 2006
    Posts
    15

    Re: How can I reverse the color in the screen?

    Thank you ,Microsoft2 and ronal29.

    I have solve the problem.BitmapUtil doesn't support the EColor16M ,So I use the DataAdress() in bitmap to get the bitmap memory adress,and reverse it pixel by pixel.

    Thanks for your help when I'm in desperation.

    Sanmu163.

Similar Threads

  1. Black screen when playing Video on Nokia 6680
    By cbazza@poliplus.com in forum Mobile Java Media (Graphics & Sounds)
    Replies: 3
    Last Post: 2007-01-26, 17:24
  2. Direct Screen Access (Please Comment!)
    By earamsey in forum Symbian
    Replies: 1
    Last Post: 2006-07-28, 18:34
  3. Full screen splash screen
    By jitendrachhajed in forum Symbian
    Replies: 1
    Last Post: 2005-07-11, 08:01
  4. Why use direct screen access?
    By Kalderas in forum Symbian
    Replies: 3
    Last Post: 2003-10-10, 14:29
  5. how to change Screen from Form to FullCanvas
    By ihadreampp in forum Mobile Java General
    Replies: 3
    Last Post: 2003-08-15, 08:50

Posting Permissions

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