I recently used the bitmap class and encountered many difficulties. I wrote it down and shared it with my friends who encountered the same difficulties.
1. If you want to upload an image to the server, the speed of calling Sina's interface is different from that of Sina's own upload. After finding the reason for one day, I found that Sina compresses the image:
Bitmap. Compress (bitmap. compressformat. JPEG, 100, baos );
The first parameter is the format of the compressed image. In particular, when the quality of the compressed image is the same, the compressed image in JPEG format is much smaller than that in PNG. Therefore, JPEG is recommended for compression.
The second parameter is that the quality of the compressed image is 0-100. 0 indicates that the image quality is the least compressed, and 100 indicates that the image quality is the maximum after compression.
The third parameter is the output stream at which point the image is compressed.
2. two common methods of Bitmap
Proportional Scaling:
Bitmap = bitmap. createscaledbitmap (bitmap, width, height, false );
Part of the screenshot:
Bitmap = bitmap. createbitmap (bitmap, X, Y, width, height );
3. It is also a fatal problem that memory overflow must be recycled when bitmap is not used.
If (Bitmap! = NULL &&! Bitmap.Isrecycled ())
){
Bitmap. Recycle ();
Bitmap = NULL;
}