Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 795305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:27:32+00:00 2026-05-14T22:27:32+00:00

I am using the following code to resize and save the file in to

  • 0

I am using the following code to resize and save the file in to the blackberry device. After image scale I try to write image file into device. But it gives the same data. (Height and width of the image are same).I have to make rescaled image file.Can anyone help me ???

class ResizeImage extends MainScreen implements FieldChangeListener
{
private String path=”file:///SDCard/BlackBerry/pictures/test.jpg”;
private ButtonField btn;
ResizeImage()
{
btn=new ButtonField(“Write File”);
btn.setChangeListener(this);
add(btn);
}
public void fieldChanged(Field field, int context)
{
if (field == btn)
{
try
{
InputStream inputStream = null;
//Get File Connection
FileConnection fileConnection = (FileConnection) Connector.open(path);
if (fileConnection.exists())
{
inputStream = fileConnection.openInputStream();
//byte data[]=inputStream.toString().getBytes();

                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    int j = 0;
                    while((j=inputStream.read()) != -1) {
                    baos.write(j);
                    }
                    byte data[] = baos.toByteArray();                
                    inputStream.close();
                    fileConnection.close();  

                    WriteFile("file:///SDCard/BlackBerry/pictures/org_Image.jpg",data);           


                    EncodedImage  eImage = EncodedImage.createEncodedImage(data,0,data.length);                               
                    int scaleFactorX = Fixed32.div(Fixed32.toFP(eImage.getWidth()), Fixed32.toFP(80));
                    int scaleFactorY = Fixed32.div(Fixed32.toFP(eImage.getHeight()), Fixed32.toFP(80));
                    eImage=eImage.scaleImage32(scaleFactorX, scaleFactorY);   

                    WriteFile("file:///SDCard/BlackBerry/pictures/resize.jpg",eImage.getData());

                    BitmapField bit=new BitmapField(eImage.getBitmap());                       
                    add(bit);

                }       
            }
            catch(Exception e)
            {
                System.out.println("Exception is ==> "+e.getMessage());
            }

        }
   }


   void WriteFile(String fileName,byte[] data)
   {
       FileConnection fconn = null;
        try
        {
            fconn = (FileConnection) Connector.open(fileName,Connector.READ_WRITE);
        } 
        catch (IOException e) 
        {
            System.out.print("Error opening file");
        }

        if (fconn.exists())
        try 
        {
            fconn.delete();
        }
        catch (IOException e)
        {
            System.out.print("Error deleting file");
        }
        try 
        {
            fconn.create();
        }
        catch (IOException e) 
        {
            System.out.print("Error creating file");
        }
        OutputStream out = null;
        try
        {
            out = fconn.openOutputStream();
        } 
        catch (IOException e) {
            System.out.print("Error opening output stream");
        }

        try 
        {
            out.write(data);
        }
        catch (IOException e) {
            System.out.print("Error writing to output stream");
        }

        try
        {
            fconn.close();
        } 
        catch (IOException e) {
            System.out.print("Error closing file");
        }
    }

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:27:32+00:00Added an answer on May 14, 2026 at 10:27 pm

    Check out getScaledHeight() and getScaledWidth() in EncodedImage.

    It’s a dirty RIM trick.

    If you peel the bitmap out with getBitmap() that will have valid getHeight() and getWidth().

    Then if you want to save that scaled image as a jpeg you need to re-encode.

    e.g.

    Bitmap scaledBMP = scaledEI.getBitmap();
    JPEGEncodedImage finalJPEG = JPEGEncodedImage.encode(scaledBMP, 80); // int arg is quality
    raw_media_bytes = finalJPEG.getData();
    raw_length = finalJPEG.getLength();
    raw_offset = finalJPEG.getOffset();
    
    // don't forget to use the length and offset info, because getData() is
    // not guaranteed to work by itself.
    

    AFAIK, pre-5.0 at least there’s no native in-jpeg scaling w/o converting to bitmap.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following code to query a database from my jsp, but I'd
Using the following code I get a nice formatted string: Request.QueryString.ToString Gives me something
I've been using the following code to open Office Documents, PDF, etc. on my
I am using following PHP code to connect to MS Access database: $odb_conn =
I am currently using the following code to create a web request: Dim myRequest
I'm using the following code within the JCProperty class to retrieve data from a
I'm using the following code, using the SharpZipLib library, to add files to a
I'm using the following code to loop through a directory to print out the
I am using the following code: <?php $stock = $_GET[s]; //returns stock ticker symbol
I am using the following code to check if a variable is not nil

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.