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 8050279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:01:45+00:00 2026-06-05T07:01:45+00:00

I used the the below code to rotate the image. There is no problem

  • 0

I used the the below code to rotate the image. There is no problem in image rotation, but when i rotate the image the image pixels was reduced. if i rotate continuously means the image will disappeared. How can i solve this problem.

main.xml

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/test" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="66dp"
        android:text="Click here to Rotate" />

</RelativeLayout>

ImageResizeTestActivity.java

public class ImageResizeTestActivity extends Activity {
    /** Called when the activity is first created. */
    Button click;
    ImageView img;
    static File rotated_File;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        click = (Button) findViewById(R.id.button1);
        img = (ImageView) findViewById(R.id.imageView1);
        String fname = "Rotated_Image.jpg";
        rotated_File = new File("/sdcard/" + fname);
        click.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                if (!(rotated_File.exists())) {
                    Log.v("Inside if", "if");
                    rotateImage();
                } else {
                    Log.v("Inside else", "else");
                    rotateImage(rotated_File.getAbsolutePath());
                }

            }
        });
    }

    protected void rotateImage(String absolutePath) {
        // TODO Auto-generated method stub
        Bitmap myImg = BitmapFactory.decodeFile(absolutePath);

        Matrix matrix = new Matrix();
        matrix.postRotate(90);

        Bitmap rotated = Bitmap.createBitmap(myImg, 0, 0, myImg.getWidth(),
                myImg.getHeight(), matrix, true);
        saveImage_Rotate(rotated);
        img.setImageBitmap(rotated);
    }

    protected void rotateImage() {
        // TODO Auto-generated method stub
        Bitmap myImg = BitmapFactory.decodeResource(getResources(),
                R.drawable.test);

        Matrix matrix = new Matrix();
        matrix.postRotate(90);

        Bitmap rotated = Bitmap.createBitmap(myImg, 0, 0, myImg.getWidth(),
                myImg.getHeight(), matrix, true);
        saveImage_Rotate(rotated);
        img.setImageBitmap(rotated);
    }

    static void saveImage_Rotate(Bitmap dest2) {

        if (rotated_File.exists())
            rotated_File.delete();
        try {
            FileOutputStream out = new FileOutputStream(rotated_File);
            dest2.compress(Bitmap.CompressFormat.JPEG, 100, out);
            out.flush();
            out.close();

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

Initially my Image is after rotating Rotated image

  • 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-06-05T07:01:48+00:00Added an answer on June 5, 2026 at 7:01 am

    A quick look on the problem. You save the jpg several times, and during the (lossy)compression it will degrade more and more.

    I’d suggest you use png instead

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

Sidebar

Related Questions

i used the code below to show the game center but if I rotate
I used the below code to upload multiple files. Its working absolutely fine but
I have some problem with my cfml website. I have used the below code
I am having a very specific problem in JQuery The code below is used
I am trying out WebDriverBacked selenium. I used the below code. But, it gives
I displayed Image from the web. For xml I used below code: main.xml: <com.imloader.LoaderImageView
I have used the below code but its not showing the msgbox. What is
I used below code to read sub context news from bbc site,but it is
I used below code for free hand drawing on the whole view: UIGraphicsBeginImageContext(self.view.frame.size); [drawImage.image
I am trying to make a jquery function, and used below code, but not

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.