j2me中放大和缩小图片的方法
2013-07-13 22:42
274 查看
/*************************************************************************** * http://blog.csdn.net/the3gwireless * 放大图片的方法 */public static Image zoomInImage(Image img)
{ int[] rgbOutput = null; int width = 0, height = 0; int[] rgbInput = null; try { width = img.getWidth(); height = img.getHeight(); rgbInput = new int[width * height]; rgbOutput = new int[(width << 1) * (height << 1)]; img.getRGB(rgbInput, 0, width, 0, 0,
width, height); int i, j, k; k = 0; for (i = 0; i < (height << 1); i += 2) { for (j = 0; j < (width << 1); j += 2) { if (j < 3) { // System.out.println(i * (width << 1) + j); // System.out.println((i + 1) * (width << 1) + j); // System.out.println(i * (width
<< 1) + j + 1); // System.out.println((i + 1) * (width << 1) + j + 1); } rgbOutput[i * (width << 1) + j] = rgbInput[k]; rgbOutput[(i + 1) * (width << 1) + j] = rgbInput[k]; rgbOutput[i * (width << 1) + j + 1] = rgbInput[k]; rgbOutput[(i + 1) * (width << 1)
+ j + 1] = rgbInput[k]; k++; } } return Image.createRGBImage(rgbOutput,
width << 1, height << 1, true); } catch (OutOfMemoryError e)
{ // e.printStackTrace(); ImageAlbum.showAlert("图像尺寸太大,不能完成此操作."); return img; } finally { rgbOutput = null; rgbInput = null; } } /*************************************************************************** * 缩小图片的方法 */public static Image zoomOutImage(Image img)
{ int[] rgbOutput = null; int width = 0, height = 0; int[] rgbInput = null; try { width = img.getWidth(); height = img.getHeight(); // System.out.println(width >> 1); // System.out.println(height >> 1); rgbInput = new int[width * height]; rgbOutput = new
int[(width >> 1) * (height >> 1)]; img.getRGB(rgbInput, 0, width, 0, 0, width, height); int i, j, k, k1; k = 0; k1 = 0; // System.out.println(height); // System.out.println(width); for (i = 0; i < height; i++) { for (j = 0; j < width; j += 2) { if (i % 2 ==
0) { if (k1 > width * height - 1 || k > (width >> 1) * (height >> 1) - 1) { // System.out.println("k=" + k); // System.out.println("k1=" + k1); break; } rgbOutput[k] = rgbInput[k1]; k++; k1 += 2; // System.out.println(k); // System.out.println(k1); } else
{ k1 += 2; } } } return Image.createRGBImage(rgbOutput,
width >> 1, height >> 1, true); } catch (OutOfMemoryError e)
{ // e.printStackTrace(); ImageAlbum.showAlert("图像尺寸太大,不能完成此操作."); return img; } finally { rgbOutput = null; rgbInput = null; } }
{ int[] rgbOutput = null; int width = 0, height = 0; int[] rgbInput = null; try { width = img.getWidth(); height = img.getHeight(); rgbInput = new int[width * height]; rgbOutput = new int[(width << 1) * (height << 1)]; img.getRGB(rgbInput, 0, width, 0, 0,
width, height); int i, j, k; k = 0; for (i = 0; i < (height << 1); i += 2) { for (j = 0; j < (width << 1); j += 2) { if (j < 3) { // System.out.println(i * (width << 1) + j); // System.out.println((i + 1) * (width << 1) + j); // System.out.println(i * (width
<< 1) + j + 1); // System.out.println((i + 1) * (width << 1) + j + 1); } rgbOutput[i * (width << 1) + j] = rgbInput[k]; rgbOutput[(i + 1) * (width << 1) + j] = rgbInput[k]; rgbOutput[i * (width << 1) + j + 1] = rgbInput[k]; rgbOutput[(i + 1) * (width << 1)
+ j + 1] = rgbInput[k]; k++; } } return Image.createRGBImage(rgbOutput,
width << 1, height << 1, true); } catch (OutOfMemoryError e)
{ // e.printStackTrace(); ImageAlbum.showAlert("图像尺寸太大,不能完成此操作."); return img; } finally { rgbOutput = null; rgbInput = null; } } /*************************************************************************** * 缩小图片的方法 */public static Image zoomOutImage(Image img)
{ int[] rgbOutput = null; int width = 0, height = 0; int[] rgbInput = null; try { width = img.getWidth(); height = img.getHeight(); // System.out.println(width >> 1); // System.out.println(height >> 1); rgbInput = new int[width * height]; rgbOutput = new
int[(width >> 1) * (height >> 1)]; img.getRGB(rgbInput, 0, width, 0, 0, width, height); int i, j, k, k1; k = 0; k1 = 0; // System.out.println(height); // System.out.println(width); for (i = 0; i < height; i++) { for (j = 0; j < width; j += 2) { if (i % 2 ==
0) { if (k1 > width * height - 1 || k > (width >> 1) * (height >> 1) - 1) { // System.out.println("k=" + k); // System.out.println("k1=" + k1); break; } rgbOutput[k] = rgbInput[k1]; k++; k1 += 2; // System.out.println(k); // System.out.println(k1); } else
{ k1 += 2; } } } return Image.createRGBImage(rgbOutput,
width >> 1, height >> 1, true); } catch (OutOfMemoryError e)
{ // e.printStackTrace(); ImageAlbum.showAlert("图像尺寸太大,不能完成此操作."); return img; } finally { rgbOutput = null; rgbInput = null; } }
相关文章推荐
- .Net实现上传图片按比例自动缩小或放大的方法
- JS简单的图片放大缩小的两种方法
- js实现双击图片放大单击缩小的方法
- jQuery实现滚动鼠标放大缩小图片的方法(附demo源码下载)
- JS实现图片放大缩小的方法
- JS简单的图片放大缩小的两种方法
- CSS实现图片放大缩小的几种方法
- Android实现旋转,放大,缩小图片的方法
- J2ME插值算法实现图片的放大缩小
- j2me 放大缩小图片代码
- 实现SVG图片放大缩小(zoom)与拖动(pan)的方法
- C#中Bitmap类实现对图像操作的一些方法(Asp.net(C#)-放大缩小图片尺寸)
- js实现图片放大缩小功能后进行复杂排序的方法
- 鼠标移入,图片放大缩小的方法css方式
- JS简单的图片放大缩小的两种方法
- 利用PHP实现图片等比例放大和缩小的方法详解
- jQuery实现滚动鼠标放大缩小图片的方法(附demo源码下载)
- JS实现图片局部放大或缩小的方法
- js实现图片放大缩小功能后进行复杂排序的方法
- js实现双击图片放大单击缩小的方法