×

Discussion Board

Results 1 to 12 of 12
  1. #1
    Regular Contributor
    Join Date
    Jul 2009
    Posts
    211

    Question Showing Image in center

    I have a bitmap of size 100X 120.

    I want to display this bitmap in the center of the rectangular area in the screeen.

    The cordinate of rectangular area is ..
    topleft(0,360)
    topright(360,360)
    bottomlft(0,480)
    botom right(360,480)

    How to do this?

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,167

    Re: Showing Image in center

    just calculate the top & left gap from the image size & screen-rect size, and then set the coordinates correct for the draw function..

  3. #3
    Regular Contributor
    Join Date
    Apr 2008
    Location
    India
    Posts
    477

    Re: Showing Image in center

    Quote Originally Posted by siva_321 View Post
    I have a bitmap of size 100X 120.

    I want to display this bitmap in the center of the rectangular area in the screeen.

    The cordinate of rectangular area is ..
    topleft(0,360)
    topright(360,360)
    bottomlft(0,480)
    botom right(360,480)

    How to do this?
    if the coordinates are fixed then wht the prob.

    draw it on the point (80,360).

  4. #4
    Super Contributor
    Join Date
    May 2005
    Location
    Hyderabad,India
    Posts
    704

    Re: Showing Image in center

    Hi,

    Use the following code:
    Code:
    TSize sz = iBitmap->SizeInPixels();
    TInt xPos,yPos;
    xPos = (Rect().Width()-sz.iWidth)/2;
    yPos = (Rect().Height()-sz.iHeight)/2;
    
    gc.BitBlt(TPoint(xPos,yPos),iBitmap);
    Thanks,
    Eswar

  5. #5
    Registered User
    Join Date
    Jul 2009
    Posts
    34

    Re: Showing Image in center

    siva do all those as u did earlier.

  6. #6
    Regular Contributor
    Join Date
    Jul 2009
    Posts
    211

    Re: Showing Image in center

    Hi,
    My coordinate of the rectangular area in the screen remains constant.
    But my bitmap size will change.
    I am scaling using the function
    Scale(&iStatus, *iBitmap, TSize(120,120),ETrue);

    and trying to draw the resulting bitmap in the center of the rectangular area inthe screen mentioned earlier.

  7. #7
    Super Contributor
    Join Date
    May 2005
    Location
    Hyderabad,India
    Posts
    704

    Re: Showing Image in center

    Hi siva,

    Instead of scaling, use the following code:

    Code:
    TSize sz = iBitmap->SizeInPixels();
    
    TInt wd =360,ht=480;
    
    if(sz.iHeight>=ht)
    		{
    		TInt percent = (sz.iHeight-ht)*100;
    		percent = percent/sz.iHeight;
    
    		sz.iHeight=sz.iHeight-((sz.iHeight)*percent/100);
    		sz.iWidth=sz.iWidth-((sz.iWidth)*percent/100);
    		}
    		if(sz.iHeight< ht)
    		{
    			TInt percent = (ht-sz.iHeight)*100;
    			percent = percent/sz.iHeight;
    
    			sz.iHeight=sz.iHeight+((sz.iHeight)*percent/100);
    			sz.iWidth=sz.iWidth+((sz.iWidth)*percent/100);			
    		}
    		if(sz.iWidth>=wd)
    			{
    			TInt percent = (sz.iWidth-wd)*100;
    			percent = percent/sz.iWidth;
    
    			sz.iHeight=sz.iHeight-((sz.iHeight)*percent/100);
    			sz.iWidth=sz.iWidth-((sz.iWidth)*percent/100);
    			}
    
    			TPoint ps;
    	ps.iX=(wd-sz.iWidth)/2;
    	ps.iY = (ht-sz.iHeight)/2;
    
    	gc.DrawBitmap(TRect(ps,sz),iImage);
    It works find for me in my app.

    Thanks,
    Eswar

  8. #8
    Regular Contributor
    Join Date
    Jul 2009
    Posts
    211

    Re: Showing Image in center

    Hi Eswar,
    Thanks.It will work fine.But I do want to maintain the aspect ratio.Thats why i am using scale().

  9. #9
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,167

    Re: Showing Image in center

    You could simply make sure you keep the aspect ratio on drawing rect creation, would save some processing on your application really..

  10. #10
    Super Contributor
    Join Date
    May 2005
    Location
    Hyderabad,India
    Posts
    704

    Re: Showing Image in center

    Quote Originally Posted by siva_321 View Post
    Hi Eswar,
    Thanks.It will work fine.But I do want to maintain the aspect ratio.Thats why i am using scale().
    Hi siva,

    Above code works for aspect ratio.

    Thanks,
    Eswar

  11. #11
    Regular Contributor
    Join Date
    Jul 2009
    Posts
    211

    Re: Showing Image in center

    Hi Eswar,
    Your code is for the whole screen(360 X 480)
    But my rectangular are is not of that size

    It is in the bottom portion of the screen..
    The cordinate of rectangular area is ..
    topleft(0,360)
    topright(360,360)
    bottomlft(0,480)
    botom right(360,480)
    My rect is of size (360 X 120) in the bottom portion

    Also if i give
    TInt wd =360,ht=120;
    It will take the top portion and draw.

  12. #12
    Super Contributor
    Join Date
    May 2005
    Location
    Hyderabad,India
    Posts
    704

    Re: Showing Image in center

    Hi,

    Code:
    TInt offset= 480-(ht); //here ht=120
    ps.iX=(wd-sz.iWidth)/2;
    ps.iY = (ht-sz.iHeight)/2;
    ps.iY+=offset;
    gc.DrawBitmap(TRect(ps,sz),iImage);
    Check with above logic.

    Thanks,
    Eswar

Similar Threads

  1. image processing-splitting&resizing
    By XenL in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2007-11-08, 09:20
  2. Opening a JPEG Image
    By ummarbhutta in forum Mobile Java Media (Graphics & Sounds)
    Replies: 8
    Last Post: 2007-02-15, 06:34
  3. saving jpeg image on grid list
    By flicker82 in forum Symbian
    Replies: 0
    Last Post: 2005-01-21, 04:22
  4. Replies: 0
    Last Post: 2003-05-12, 17:38
  5. Replies: 1
    Last Post: 1970-01-01, 02:00

Posting Permissions

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