AO Jiao Android two three things days not long before the Bitmap. compress

Source: Internet
Author: User

In other words, a long time is required for a long time. Dano Dynasty cabinet first auxiliary Kang Pei Kai Kang big bachelor, just self-use, Gu Bu self-sealing, do not think enterprising, resulting in the world together. In the midst of chaos, Apple and Microsoft took the elites from the center. Google, the new gender, has two banners in front of the camp, and says "I am free" on the left and "you know" on the right ". At this point, Jianghu haomhan does not share with each other. In this age of Bug fixing, the poor track only conforms to the trend of the times and started the Android development code industry on the 2.1 line.

Although Android adheres to Taizu's unity of all the forces that can be united in civilian philosophy, he was born in a noble family. A little proud, a little ungrounded.

In the early spring morning, the poor Tao just ended the development of an image editing function. On QQ, he spoke with many friends about the current trend. Speaking of the highlights, the poor can not help but shake hands free to issue the Times report, quite the momentum of the year of Wu houlongzhong, not proud. Suddenly jingle, I saw a prompt box in the lower-right corner of the screen. A Bug report is sent to the poor. Suddenly, just now the good mood burst, and then reluctantly opened a report Link, I saw the above: Image is destroyed. There was a dark line on the poor road. With the normal thinking of humans, I really couldn't figure out what the Image is destroyed. Fortunately, the tester gave a picture showing the bug and clicked it to see it again. The full-screen mosaic is filled with shadows. Although it is a test, it cannot be used to browse and collect adult images. This is a lot of exposure, full screen mosaic, think of this poor road secretly despise this tester, so I can take a mosaic beautiful figure, give it to joy. It's better to be happy. At this time, the poor man calmly asked the tester about the bug, but the result was an amazing message. This mosaic was not naturally formed, but was uploaded, edited, and saved by the image, load, edit, and save it. This effect is achieved when it is repeated several times every week. When I heard this, the poor man sighed and quickly took the test picture and began to look for the reason.

Return to the seat and open the picture. It's a guy who has 20 higher IQ than lub. He claims to only eat mutton like a gray wolf (see figure 1 ). After a series of operations, such as lean rotation, top, bottom, left, right, and bottom, a layer of familiar thin mosaic emerged (see figure 2 ).

Figure 1 Figure 2

Is it because the image is not accurate enough? Based on the experience of playing games, the setAntiAlias anti-sawtooth function of Paint is called to improve the painting quality. Then I raised my mind and pressed Run, but the cruel reality broke the hope of the poor. Mosaic, as the minor strong attach body, tenacious survival.

The poor track once again looked at the code and made another judgment: Is it caused by the accumulation of errors in moving coordinates when the picture is rotated or upside down? After giving up the rotation and reversing functions, I ran the program again, and the sound of Tao remained.

Is it because of the number of digits in the color of the image, but the code is always four 8 (Config. ARGB_8888.

As the saying goes, if you want to destroy it, you must first make it crazy. A test program was re-written for the poor (see the following program code ). All Editing effects are blocked, and only the loading and saving operations are retained. After the Run operation, the poor world view began to collapse. The mosaic is not moving, as if the small advertisement of traditional Chinese medicine practitioners is firmly pasted on the image.

MainActivity. xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context=".MainActivity" >        <ImageView        android:id="@+id/img"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:scaleType="fitCenter"        /></RelativeLayout>

MainActivity. java

package com.example.testcompress;import java.io.ByteArrayOutputStream;import java.io.File;import java.io.FileOutputStream;import android.os.Bundle;import android.app.Activity;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Bitmap.CompressFormat;import android.view.Menu;import android.widget.ImageView;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Bitmap bmp = BitmapFactory.decodeFile("/mnt/sdcard/wolf.jpg");for(int i = 0 ; i < 30 ; i++){ImageView mv = (ImageView)findViewById(R.id.img);mv.setImageBitmap(bmp);File file = null;try {file = new File("/mnt/sdcard/wolf_tmp.jpg");file.delete();ByteArrayOutputStream stream = new ByteArrayOutputStream();bmp.compress(CompressFormat.JPEG, 100, stream);FileOutputStream os = new FileOutputStream(file);os.write(stream.toByteArray());os.close();} catch (Exception ex) {file = null;}bmp = BitmapFactory.decodeFile("/mnt/sdcard/wolf_tmp.jpg");}}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.activity_main, menu);return true;}}

The poor man scratched his head and fell into meditation. When the sky was full of flying chips on the desktop, the poor road suddenly found that the gray wolf was actually streaking naked. Is it inappropriate for the SDK to identify it as a child and it should be handled by cavalry. As a result, desert.jpg files are suitable for all users (see figure 3 ). Facts have proved that we once again underestimated the shameless nature of mosaic, and this time the vicissitudes of the desert were treated like Cang's teacher, the mosaic of the Sky (see figure 4 ).

Figure 3 Figure 4

At this time, the computer next to my colleague came up with the familiar voice "I believe there is only one truth. In my mind, Qin Yi, Yan, and Wang Jingwei, who seems loyal and honest, is actually a Chinese thief. These names gradually converge into compress words. That's right. The final culprit is the Bitmap. compress of volv, which seems like the second brother. Due to the jpg compression algorithm, as the number of storage times increases, the loss of pixels becomes more and more serious, and finally the image is mosaic. The sly fox still cannot beat the hunter, and the poor man gave a thumbs up to the Google logo on the webpage.

In order to step on 10 thousand more feet, I tested the png format (modify the code as follows ). Similarly, they are all born from mothers. PNG images are almost lossless (see figure 5 ).

MainActivity. java

protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Bitmap bmp = BitmapFactory.decodeFile("/mnt/sdcard/wolf.png");for(int i = 0 ; i < 30 ; i++){ImageView mv = (ImageView)findViewById(R.id.img);mv.setImageBitmap(bmp);File file = null;try {file = new File("/mnt/sdcard/wolf_tmp.png");file.delete();ByteArrayOutputStream stream = new ByteArrayOutputStream();bmp.compress(CompressFormat.PNG, 100, stream);FileOutputStream os = new FileOutputStream(file);os.write(stream.toByteArray());os.close();} catch (Exception ex) {file = null;}bmp = BitmapFactory.decodeFile("/mnt/sdcard/wolf_tmp.png");}}

 

Figure 5

Therefore, in order to maintain the restoration of images, please try to use PNG images in Android development., Excluding Japanese photos. At the same time, I also wrote the prompt on the napkin I used at noon. After the paste, I shared it with zjun.

 

 

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.