안드로이드 학습의 압축 그림을 지정한 크기로
방법1:
*
*
* bitmap , 64kb,
*
* @param bitmap
* @return
*/
private Bitmap ImageCompressL(Bitmap bitmap) {
double targetwidth = Math.sqrt(64.00 * 1000);
if (bitmap.getWidth() > targetwidth || bitmap.getHeight() > targetwidth) {
// matrix
Matrix matrix = new Matrix();
//
double x = Math.max(targetwidth / bitmap.getWidth(), targetwidth
/ bitmap.getHeight());
//
matrix.postScale((float) x, (float) x);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
bitmap.getHeight(), matrix, true);
}
return bitmap;
}
방법2:
* ( )
*
* bitmap , 64kb,
*
* @param bitmap
*/
private Bitmap ImageCompress(Bitmap bitmap) {
// :KB
double maxSize = 64.00;
// bitmap , bitmap ( )
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
// KB
double mid = b.length / 1024;
// bitmap
if (mid > maxSize) {
// bitmap
double i = mid / maxSize;
//
bitmap = zoomImage(bitmap, bitmap.getWidth() / Math.sqrt(i),
bitmap.getHeight() / Math.sqrt(i));
}
return bitmap;
}
/***
*
*
* @param bgimage
* :
* @param newWidth
* :
* @param newHeight
* :
* @return
*/
public Bitmap zoomImage(Bitmap bgimage, double newWidth, double newHeight) {
//
float width = bgimage.getWidth();
float height = bgimage.getHeight();
// matrix
Matrix matrix = new Matrix();
//
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
//
matrix.postScale(scaleWidth, scaleHeight);
Bitmap bitmap = Bitmap.createBitmap(bgimage, 0, 0, (int) width,
(int) height, matrix, true);
return bitmap;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Cognos 보고서 PDF 출력의 성능 튜닝 매개 변수 검증 결과보고서를 PDF로 출력할 때 Report Service 또는 Batch Report Service 매개변수에서 PDF 출력의 글꼴과 압축을 조정할 수 있는 Cognos Administration 매개변수가 있습니다....
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.