User Tools

Site Tools


code:android-code:image-convert

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
code:android-code:image-convert [2011/09/10 18:32] – external edit 127.0.0.1code:android-code:image-convert [2016/05/05 13:07] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Android上图像处理-倒影,圆角,渐变 ====== ====== Android上图像处理-倒影,圆角,渐变 ======
 +
 Android对图片处理的函数应该是很多的,但由于平时对图像处理用到情况不多,要用到时只有不停的Google. Android对图片处理的函数应该是很多的,但由于平时对图像处理用到情况不多,要用到时只有不停的Google.
 +
 +
  
 这次要用到的图像效果比较多,有倒影,图片圆角,还有图像渐变,感谢Google,在经过我不懈的搜索后,找到了一些比较有用的做法. 这次要用到的图像效果比较多,有倒影,图片圆角,还有图像渐变,感谢Google,在经过我不懈的搜索后,找到了一些比较有用的做法.
 +
 +
  
 1.在android中2D中实现对图片的倒影: 1.在android中2D中实现对图片的倒影:
 +
 +
  
 http://blog.163.com/joe_zhpf@126/blog/static/81331086201032755840878/ http://blog.163.com/joe_zhpf@126/blog/static/81331086201032755840878/
 +
 +
  
 2.Android 中实现倒影效果 2.Android 中实现倒影效果
 +
 +
  
 http://www.blogjava.net/lihao336/archive/2010/04/13/318163.html http://www.blogjava.net/lihao336/archive/2010/04/13/318163.html
 +
 +
  
 3.使用 2D 方法实现倒影特效  3.使用 2D 方法实现倒影特效 
 +
 +
  
 http://www.linuxgraphics.cn/android/reflection_effect_2d.html http://www.linuxgraphics.cn/android/reflection_effect_2d.html
 +
 +
  
 4.Android 图片透明度处理代码 4.Android 图片透明度处理代码
 +
 +
  
 http://blog.csdn.net/xyz_lmn/archive/2009/12/10/4978982.aspx http://blog.csdn.net/xyz_lmn/archive/2009/12/10/4978982.aspx
 +
 +
 +5.android图片处理方法
 +
 +http://gundumw100.iteye.com/blog/849729
  
 我将上面这些代码进行了整理,以适合自己的使用,现在对这些原理都不太了解,需要慢慢的去熟悉: 我将上面这些代码进行了整理,以适合自己的使用,现在对这些原理都不太了解,需要慢慢的去熟悉:
 +
 +
  
 附目前效果图: 附目前效果图:
 +
 +
  
 {{:code:android-code:image_reflection.png?|}} {{:code:android-code:image_reflection.png?|}}
 +
 +
 +
  
  
 <code java> <code java>
 +
  public static Bitmap createReflectionImageWithOrigin(Bitmap originalImage) {  public static Bitmap createReflectionImageWithOrigin(Bitmap originalImage) {
 +
  // The gap we want between the reflection and the original image  // The gap we want between the reflection and the original image
 +
  final int reflectionGap = 4;  final int reflectionGap = 4;
 +
 +
  
  // Get you bit map from drawable folder  // Get you bit map from drawable folder
 +
  // Bitmap originalImage = BitmapFactory.decodeResource(getResources(),  // Bitmap originalImage = BitmapFactory.decodeResource(getResources(),
 +
  // R.drawable.twitter_icon);  // R.drawable.twitter_icon);
 +
 +
  
  int width = originalImage.getWidth();  int width = originalImage.getWidth();
 +
  int height = originalImage.getHeight();  int height = originalImage.getHeight();
 +
 +
  
  // This will not scale but will flip on the Y axis  // This will not scale but will flip on the Y axis
 +
  Matrix matrix = new Matrix();  Matrix matrix = new Matrix();
 +
  matrix.preScale(1, -1);  matrix.preScale(1, -1);
 +
 +
  
  // Create a Bitmap with the flip matix applied to it.  // Create a Bitmap with the flip matix applied to it.
 +
  // We only want the bottom half of the image  // We only want the bottom half of the image
 +
  Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0,  Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0,
 +
  height / 2, width, height / 2, matrix, false);  height / 2, width, height / 2, matrix, false);
 +
 +
  
  // Create a new bitmap with same width but taller to fit reflection  // Create a new bitmap with same width but taller to fit reflection
 +
  Bitmap bitmapWithReflection = Bitmap.createBitmap(width,  Bitmap bitmapWithReflection = Bitmap.createBitmap(width,
 +
  (height + height / 2), Config.ARGB_8888);  (height + height / 2), Config.ARGB_8888);
 +
 +
  
  // Create a new Canvas with the bitmap that's big enough for  // Create a new Canvas with the bitmap that's big enough for
 +
  // the image plus gap plus reflection  // the image plus gap plus reflection
 +
  Canvas canvas = new Canvas(bitmapWithReflection);  Canvas canvas = new Canvas(bitmapWithReflection);
 +
  // Draw in the original image  // Draw in the original image
 +
  canvas.drawBitmap(originalImage, 0, 0, null);  canvas.drawBitmap(originalImage, 0, 0, null);
 +
  // Draw in the gap  // Draw in the gap
 +
  Paint deafaultPaint = new Paint();  Paint deafaultPaint = new Paint();
 +
  canvas  canvas
 +
  .drawRect(0, height, width, height + reflectionGap,  .drawRect(0, height, width, height + reflectionGap,
 +
  deafaultPaint);  deafaultPaint);
 +
  // Draw in the reflection  // Draw in the reflection
 +
  canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);  canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
 +
 +
  
  // Create a shader that is a linear gradient that covers the reflection  // Create a shader that is a linear gradient that covers the reflection
 +
  Paint paint = new Paint();  Paint paint = new Paint();
 +
  LinearGradient shader = new LinearGradient(0,  LinearGradient shader = new LinearGradient(0,
 +
  originalImage.getHeight(), 0, bitmapWithReflection.getHeight()  originalImage.getHeight(), 0, bitmapWithReflection.getHeight()
 +
  + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP);  + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP);
 +
  // Set the paint to use this shader (linear gradient)  // Set the paint to use this shader (linear gradient)
 +
  paint.setShader(shader);  paint.setShader(shader);
 +
  // Set the Transfer mode to be porter duff and destination in  // Set the Transfer mode to be porter duff and destination in
 +
  paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));  paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
 +
  // Draw a rectangle using the paint with our linear gradient  // Draw a rectangle using the paint with our linear gradient
 +
  canvas.drawRect(0, height, width, bitmapWithReflection.getHeight()  canvas.drawRect(0, height, width, bitmapWithReflection.getHeight()
 +
  + reflectionGap, paint);  + reflectionGap, paint);
 +
 +
  
  return bitmapWithReflection;  return bitmapWithReflection;
 +
  }  }
 +
 +
  
  public static Bitmap createReflectionImageWithNoOrigin(Bitmap originalImage) {  public static Bitmap createReflectionImageWithNoOrigin(Bitmap originalImage) {
 +
  // The gap we want between the reflection and the original image  // The gap we want between the reflection and the original image
 +
  final int reflectionGap = 4;  final int reflectionGap = 4;
 +
 +
  
  // Get you bit map from drawable folder  // Get you bit map from drawable folder
 +
  // Bitmap originalImage = BitmapFactory.decodeResource(getResources(),  // Bitmap originalImage = BitmapFactory.decodeResource(getResources(),
 +
  // R.drawable.twitter_icon);  // R.drawable.twitter_icon);
 +
 +
  
  int width = originalImage.getWidth();  int width = originalImage.getWidth();
 +
  int height = originalImage.getHeight();  int height = originalImage.getHeight();
 +
 +
  
  // This will not scale but will flip on the Y axis  // This will not scale but will flip on the Y axis
 +
  Matrix matrix = new Matrix();  Matrix matrix = new Matrix();
 +
  matrix.preScale(1, -1);  matrix.preScale(1, -1);
 +
 +
  
  // Create a Bitmap with the flip matix applied to it.  // Create a Bitmap with the flip matix applied to it.
 +
  // We only want the bottom half of the image  // We only want the bottom half of the image
 +
  int divider = 8;  int divider = 8;
 +
 +
  
  Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height  Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height
 +
  / divider * (divider - 1), width, height / divider, matrix,  / divider * (divider - 1), width, height / divider, matrix,
 +
  false);  false);
 +
 +
  
  // Create a new bitmap with same width but taller to fit reflection  // Create a new bitmap with same width but taller to fit reflection
 +
  Bitmap bitmapWithReflection2 = Bitmap.createBitmap(width, height / 5,  Bitmap bitmapWithReflection2 = Bitmap.createBitmap(width, height / 5,
 +
  Config.ARGB_8888);  Config.ARGB_8888);
 +
 +
  
  // Create a new Canvas with the bitmap that's big enough for  // Create a new Canvas with the bitmap that's big enough for
 +
  // the image plus gap plus reflection  // the image plus gap plus reflection
 +
  Canvas canvas = new Canvas(reflectionImage);  Canvas canvas = new Canvas(reflectionImage);
 +
  // Draw in the reflection  // Draw in the reflection
 +
  canvas.drawBitmap(reflectionImage, 0, 0, null);  canvas.drawBitmap(reflectionImage, 0, 0, null);
 +
 +
  
  // Create a shader that is a linear gradient that covers the reflection  // Create a shader that is a linear gradient that covers the reflection
 +
  Paint paint = new Paint();  Paint paint = new Paint();
 +
  LinearGradient shader = new LinearGradient(0,  LinearGradient shader = new LinearGradient(0,
 +
  originalImage.getHeight(), 0, reflectionImage.getHeight(),  originalImage.getHeight(), 0, reflectionImage.getHeight(),
 +
  0x70ffffff, 0x00ffffff, TileMode.CLAMP);  0x70ffffff, 0x00ffffff, TileMode.CLAMP);
 +
  // Set the paint to use this shader (linear gradient)  // Set the paint to use this shader (linear gradient)
 +
  paint.setShader(shader);  paint.setShader(shader);
 +
  // Set the Transfer mode to be porter duff and destination in  // Set the Transfer mode to be porter duff and destination in
 +
  paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));  paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
 +
  // Draw a rectangle using the paint with our linear gradient  // Draw a rectangle using the paint with our linear gradient
 +
  canvas.drawRect(0, height/divider, width, reflectionImage.getHeight(), paint);  canvas.drawRect(0, height/divider, width, reflectionImage.getHeight(), paint);
 +
 +
  
  return reflectionImage;  return reflectionImage;
 +
  }  }
 +
 +
  
  public static Bitmap setAlpha(Bitmap sourceImg, int number) {  public static Bitmap setAlpha(Bitmap sourceImg, int number) {
 +
  int[] argb = new int[sourceImg.getWidth() * sourceImg.getHeight()];  int[] argb = new int[sourceImg.getWidth() * sourceImg.getHeight()];
 +
  sourceImg.getPixels(argb, 0, sourceImg.getWidth(), 0, 0, sourceImg  sourceImg.getPixels(argb, 0, sourceImg.getWidth(), 0, 0, sourceImg
 +
  .getWidth(), sourceImg.getHeight());//Get the ARGB Value of the image  .getWidth(), sourceImg.getHeight());//Get the ARGB Value of the image
 +
  number = number * 255 / 100;  number = number * 255 / 100;
 +
  for (int i = 0; i < argb.length; i++) {  for (int i = 0; i < argb.length; i++) {
 +
  //argb = (number << 24) | (argb & 0x00ffffff);// modify the top two bit value  //argb = (number << 24) | (argb & 0x00ffffff);// modify the top two bit value
 +
  }  }
 +
  sourceImg = Bitmap.createBitmap(argb, sourceImg.getWidth(), sourceImg  sourceImg = Bitmap.createBitmap(argb, sourceImg.getWidth(), sourceImg
 +
  .getHeight(), Config.ARGB_8888);  .getHeight(), Config.ARGB_8888);
 +
 +
  
  return sourceImg;  return sourceImg;
 +
  }  }
 +
 +
  
  /**  /**
 +
  * get reflection bitmap of the original bitmap.  * get reflection bitmap of the original bitmap.
 +
  
 +
  * @param srcBitmap  * @param srcBitmap
 +
  * @return  * @return
 +
  */  */
 +
  public static Bitmap makeReflectionBitmap(Bitmap originalImage) {  public static Bitmap makeReflectionBitmap(Bitmap originalImage) {
 +
   
 +
  int width = originalImage.getWidth();  int width = originalImage.getWidth();
 +
  int height = originalImage.getHeight();  int height = originalImage.getHeight();
 +
 +
  
  // This will not scale but will flip on the Y axis  // This will not scale but will flip on the Y axis
 +
  Matrix matrix = new Matrix();  Matrix matrix = new Matrix();
 +
  matrix.preScale(1, -1);  matrix.preScale(1, -1);
 +
 +
  
  // Create a Bitmap with the flip matix applied to it.  // Create a Bitmap with the flip matix applied to it.
 +
  // We only want the bottom half of the image  // We only want the bottom half of the image
 +
  int divider = 8;  int divider = 8;
 +
 +
  
  Bitmap srcBitmap = Bitmap.createBitmap(originalImage, 0, height  Bitmap srcBitmap = Bitmap.createBitmap(originalImage, 0, height
 +
  / divider * (divider - 1), width, height / divider, matrix,  / divider * (divider - 1), width, height / divider, matrix,
 +
  false);  false);
 +
   
 +
  //srcBitmap=originalImage;  //srcBitmap=originalImage;
 +
  int bmpWidth = srcBitmap.getWidth();  int bmpWidth = srcBitmap.getWidth();
 +
  int bmpHeight = srcBitmap.getHeight();  int bmpHeight = srcBitmap.getHeight();
 +
  int[] pixels = new int[bmpWidth * bmpHeight * 4];  int[] pixels = new int[bmpWidth * bmpHeight * 4];
 +
  srcBitmap.getPixels(pixels, 0, bmpWidth, 0, 0, bmpWidth, bmpHeight);  srcBitmap.getPixels(pixels, 0, bmpWidth, 0, 0, bmpWidth, bmpHeight);
 +
 +
  
  // get reversed bitmap  // get reversed bitmap
 +
  Bitmap reverseBitmap = Bitmap.createBitmap(bmpWidth, bmpHeight,  Bitmap reverseBitmap = Bitmap.createBitmap(bmpWidth, bmpHeight,
 +
  Bitmap.Config.ARGB_8888);  Bitmap.Config.ARGB_8888);
 +
  for (int y = 0; y < bmpHeight; y++) {  for (int y = 0; y < bmpHeight; y++) {
 +
  reverseBitmap.setPixels(pixels, y * bmpWidth, bmpWidth, 0,  reverseBitmap.setPixels(pixels, y * bmpWidth, bmpWidth, 0,
 +
  bmpHeight - y - 1, bmpWidth, 1);  bmpHeight - y - 1, bmpWidth, 1);
 +
  }  }
 +
 +
  
  // get reflection bitmap based on the reversed one  // get reflection bitmap based on the reversed one
 +
  reverseBitmap.getPixels(pixels, 0, bmpWidth, 0, 0, bmpWidth, bmpHeight);  reverseBitmap.getPixels(pixels, 0, bmpWidth, 0, 0, bmpWidth, bmpHeight);
 +
  Bitmap reflectionBitmap = Bitmap.createBitmap(bmpWidth, bmpHeight,  Bitmap reflectionBitmap = Bitmap.createBitmap(bmpWidth, bmpHeight,
 +
  Bitmap.Config.ARGB_8888);  Bitmap.Config.ARGB_8888);
 +
  int alpha = 0x00000000;  int alpha = 0x00000000;
 +
  for (int y = 0; y < bmpHeight; y++) {  for (int y = 0; y < bmpHeight; y++) {
 +
  for (int x = 0; x < bmpWidth; x++) {  for (int x = 0; x < bmpWidth; x++) {
 +
  int index = y * bmpWidth + x;  int index = y * bmpWidth + x;
 +
  int r = (pixels[index] >> 16) & 0xff;  int r = (pixels[index] >> 16) & 0xff;
 +
  int g = (pixels[index] >> 8) & 0xff;  int g = (pixels[index] >> 8) & 0xff;
 +
  int b = pixels[index] & 0xff;  int b = pixels[index] & 0xff;
 +
 +
  
  pixels[index] = alpha | (r << 16) | (g << 8) | b;  pixels[index] = alpha | (r << 16) | (g << 8) | b;
 +
 +
  
  reflectionBitmap.setPixel(x, y, pixels[index]);  reflectionBitmap.setPixel(x, y, pixels[index]);
 +
  }  }
 +
  alpha = alpha + 0x01000000;  alpha = alpha + 0x01000000;
 +
  }  }
 +
  return reflectionBitmap;  return reflectionBitmap;
 +
  }  }
 +
 +
  
   
 +
  /**  /**
 +
  * Set the Bitmap alpha  * Set the Bitmap alpha
 +
  * @param srcBitmap  * @param srcBitmap
 +
  * @return  * @return
 +
  */  */
 +
  public static Bitmap setAlpha(Bitmap srcBitmap){  public static Bitmap setAlpha(Bitmap srcBitmap){
 +
  int bmpWidth = srcBitmap.getWidth();  int bmpWidth = srcBitmap.getWidth();
 +
  int bmpHeight = srcBitmap.getHeight();  int bmpHeight = srcBitmap.getHeight();
 +
  int[] pixels = new int[bmpWidth * bmpHeight * 4];  int[] pixels = new int[bmpWidth * bmpHeight * 4];
 +
  srcBitmap.getPixels(pixels, 0, bmpWidth, 0, 0, bmpWidth, bmpHeight);  srcBitmap.getPixels(pixels, 0, bmpWidth, 0, 0, bmpWidth, bmpHeight);
 +
  // get reflection bitmap based on the reversed one  // get reflection bitmap based on the reversed one
 +
  // Bitmap reverseBitmap = Bitmap.createBitmap(bmpWidth, bmpHeight,  // Bitmap reverseBitmap = Bitmap.createBitmap(bmpWidth, bmpHeight,
 +
  // Bitmap.Config.ARGB_8888);  // Bitmap.Config.ARGB_8888);
 +
  // srcBitmap.getPixels(pixels, 0, bmpWidth, 0, 0, bmpWidth, bmpHeight);  // srcBitmap.getPixels(pixels, 0, bmpWidth, 0, 0, bmpWidth, bmpHeight);
 +
  Bitmap reflectionBitmap = Bitmap.createBitmap(bmpWidth, bmpHeight,  Bitmap reflectionBitmap = Bitmap.createBitmap(bmpWidth, bmpHeight,
 +
  Bitmap.Config.ARGB_8888);  Bitmap.Config.ARGB_8888);
 +
  //int alpha = 0x88ffffff/10;  //int alpha = 0x88ffffff/10;
 +
  int alpha = 0x01000000*100;  int alpha = 0x01000000*100;
 +
  Utils.log("bmpWidth="+bmpWidth+",bmpHeight="+bmpHeight);  Utils.log("bmpWidth="+bmpWidth+",bmpHeight="+bmpHeight);
 +
  for (int y = 0; y < bmpHeight; y++) {  for (int y = 0; y < bmpHeight; y++) {
 +
  Utils.log("alpha="+alpha);  Utils.log("alpha="+alpha);
 +
  for (int x = 0; x < bmpWidth; x++) {  for (int x = 0; x < bmpWidth; x++) {
 +
  int index = y * bmpWidth + x;  int index = y * bmpWidth + x;
 +
  int r = (pixels[index] >> 16) & 0xff;  int r = (pixels[index] >> 16) & 0xff;
 +
  int g = (pixels[index] >> 8) & 0xff;  int g = (pixels[index] >> 8) & 0xff;
 +
  int b = pixels[index] & 0xff;  int b = pixels[index] & 0xff;
 +
 +
  
  pixels[index] = alpha | (r << 16) | (g << 8) | b;  pixels[index] = alpha | (r << 16) | (g << 8) | b;
 +
 +
  
  reflectionBitmap.setPixel(x, y, pixels[index]);  reflectionBitmap.setPixel(x, y, pixels[index]);
 +
  }  }
 +
   
 +
  alpha = alpha - 0x01000000*10;  alpha = alpha - 0x01000000*10;
 +
   
 +
  }  }
 +
  return reflectionBitmap;  return reflectionBitmap;
 +
  }  }
 +
 +
 +
  
  
  public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {  public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
 +
  Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap  Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
 +
  .getHeight(), Config.ARGB_8888);  .getHeight(), Config.ARGB_8888);
 +
  Canvas canvas = new Canvas(output);  Canvas canvas = new Canvas(output);
 +
 +
  
  final int color = 0xff424242;  final int color = 0xff424242;
 +
  final Paint paint = new Paint();  final Paint paint = new Paint();
 +
  final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());  final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
 +
  final RectF rectF = new RectF(rect);  final RectF rectF = new RectF(rect);
 +
  final float roundPx = 5;  final float roundPx = 5;
 +
 +
  
  paint.setAntiAlias(true);  paint.setAntiAlias(true);
 +
  canvas.drawARGB(0, 0, 0, 0);  canvas.drawARGB(0, 0, 0, 0);
 +
  paint.setColor(color);  paint.setColor(color);
 +
  canvas.drawRoundRect(rectF, roundPx, roundPx, paint);  canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
 +
 +
  
  paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));  paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
 +
  canvas.drawBitmap(bitmap, rect, rect, paint);  canvas.drawBitmap(bitmap, rect, rect, paint);
 +
 +
  
  return output;  return output;
 +
  }  }
 +
 +
  
 </code> </code>
 +
 +====== 图像等比例伸缩 ======
 +<code java>
 +    public static Bitmap createFixedBitmapWithImageView(ImageView imageView, Bitmap bitmap) {
 +        float bitmapHeight = bitmap.getHeight();
 +        float bitmapWidth = bitmap.getWidth();
 +
 +        float imageViewWidth = imageView.getWidth();
 +        float imageViewHeight = imageView.getHeight();
 +
 +        float imageViewRate = (float) imageViewWidth / (float) imageViewHeight;
 +        float bitmapRate = (float) bitmapWidth / (float) bitmapHeight;
 +        float newWidth = 0;
 +        float newHeight = 0;
 +        if (bitmapHeight > imageViewHeight && bitmapWidth > imageViewWidth) {
 +            if (bitmapRate > imageViewRate) {
 +                newWidth = imageViewWidth;
 +                newHeight = (imageViewWidth / bitmapWidth) * imageViewHeight;
 +            } else {
 +                newHeight = imageViewHeight;
 +                newWidth = (imageViewHeight / bitmapHeight) * bitmapWidth;
 +            }
 +        } else if (bitmapHeight >= imageViewHeight && bitmapWidth <= imageViewWidth) {
 +            if (bitmapRate > imageViewRate) {
 +                newWidth = imageViewWidth;
 +                newHeight = (imageViewWidth / bitmapWidth) * imageViewHeight;
 +            } else {
 +                newHeight = imageViewHeight;
 +                newWidth = imageViewHeight / bitmapHeight * bitmapWidth;
 +            }
 +        } else if (bitmapHeight < imageViewHeight && bitmapWidth > imageViewWidth) {
 +            if (bitmapRate > imageViewRate) {
 +                newWidth = imageViewWidth;
 +                newHeight = (imageViewWidth / bitmapWidth) * imageViewHeight;
 +            } else {
 +                newHeight = imageViewHeight;
 +                newWidth = (imageViewHeight / bitmapHeight) * bitmapWidth;
 +            }
 +        } else {
 +            if (bitmapRate > imageViewRate) {
 +                newWidth = imageViewWidth;
 +                newHeight = (imageViewWidth) / bitmapWidth * imageViewHeight;
 +            } else {
 +                newHeight = imageViewHeight;
 +                newWidth = (imageViewHeight / bitmapHeight) * bitmapWidth;
 +            }
 +        }
 +
 +        Bitmap resizedBitmap = resizeImage(bitmap, (int) newWidth, (int) newHeight);
 +
 +        return resizedBitmap;
 +    }
 +</code>
 +
/var/www/dokuwiki/wiki/data/attic/code/android-code/image-convert.1315650730.txt.gz · Last modified: 2016/05/05 13:06 (external edit)