×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    4

    Fit large image to mobile screen using j2me

    I have 1600*1200 image and screen size 240*300 .
    Is there any method to fit image to screen size using j2me?
    And in java, int arr[]=new int[50]
    If i use arr upto arr[25] , is it possible to deallocate memory from arr[26] to arr[49] without copying these bytes to another array
    Can any one help me

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: Fit large image to mobile screen using j2me

    Code:
    // screenWidth, srcHeight are the target screen height & width
    
     private Image resizeImage(Image src) {
          int srcWidth = src.getWidth();
          int srcHeight = src.getHeight();
          Image tmp = Image.createImage(screenWidth, srcHeight);
          Graphics g = tmp.getGraphics();
          int ratio = (srcWidth << 16) / screenWidth;
          int pos = ratio/2;
    
          //Horizontal Resize        
    
          for (int x = 0; x < screenWidth; x++) {
              g.setClip(x, 0, 1, srcHeight);
              g.drawImage(src, x - (pos >> 16), 0, Graphics.LEFT | Graphics.TOP);
              pos += ratio;
          }
    
          Image resizedImage = Image.createImage(screenWidth, screenHeight);
          g = resizedImage.getGraphics();
          ratio = (srcHeight << 16) / screenHeight;
          pos = ratio/2;        
    
          //Vertical resize
    
          for (int y = 0; y < screenHeight; y++) {
              g.setClip(0, y, screenWidth, 1);
              g.drawImage(tmp, 0, y - (pos >> 16), Graphics.LEFT | Graphics.TOP);
              pos += ratio;
          }
          return resizedImage;
    
      }//resize image
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

Similar Threads

  1. How to put the sigature in touch Screen Mobile(5230) using j2me midlet
    By chandrasekaranbe in forum Mobile Java General
    Replies: 4
    Last Post: 2011-05-23, 11:02
  2. how to fit the background image to the screen size
    By amit04.kumar in forum Symbian Media (Closed)
    Replies: 6
    Last Post: 2010-09-24, 15:20
  3. diaplay a large image using scroll in J2ME
    By mramin05 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 8
    Last Post: 2009-07-02, 09:19
  4. Fit screen size on specific mobile devices
    By m1dp1d in forum Browsing and Mark-ups
    Replies: 1
    Last Post: 2006-11-14, 21:11

Posting Permissions

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