使用的getPixels从位图获取像素()。 (抛出:IllegalArgumentException) [英] getting pixels from bitmap using getpixels(). (illegalargumentexception)
问题描述
我想将数据从一个位图复制到一个int []使用的getPixels但我的code是抛出一个错误。错误是说下面。有没有人任何想法?我只是规定在Y参数为0。
20 05-04:24:08.281:ERROR / AndroidRuntime(5700):未捕获的处理程序:螺纹主力退出,由于未捕获的异常
05-04 20:24:08.296:ERROR / AndroidRuntime(5700):java.lang.IllegalArgumentException异常:Y +高度必须是< = bitmap.height()
05-04 20:24:08.296:ERROR / AndroidRuntime(5700):在android.graphics.Bitmap.checkPixelsAccess(Bitmap.java:818)
05-04 20:24:08.296:ERROR / AndroidRuntime(5700):在android.graphics.Bitmap.getPixels(Bitmap.java:771)
05-04 20:24:08.296:ERROR / AndroidRuntime(5700):在com.tecmark.Jjilapp $ TouchView.onDraw(Jjilapp.java:206)INT []个像素=新INT [myBitmap.getHeight()* myBitmap.getWidth()];
myBitmap.getPixels(像素,0,myBitmap.getWidth(),0,0,myBitmap.getHeight(),myBitmap.getWidth()); 的for(int i = 0; I< myBitmap.getHeight()* myBitmap.getWidth();我++){
Log.e(TAG,像素+ I ++像素[I]);
您有您的宽和高切换。
myBitmap.getPixels(像素,0,myBitmap.getWidth(),0,0,myBitmap.getHeight(),myBitmap.getWidth());
VS
公共无效的getPixels(INT []像素,诠释抵消,诠释步幅,诠释的x,INT Y,INT宽度,高度INT)
<一href=\"http://developer.android.com/reference/android/graphics/Bitmap.html#getPixels%28int%5B%5D,%20int,%20int,%20int,%20int,%20int,%20int%29\">http://developer.android.com/reference/android/graphics/Bitmap.html#getPixels(int[], INT,INT,INT,INT,INT,INT)
I'd like to copy the data from a bitmap into an int[] using getPixels but my code is throwing an error. the error is saying the following. has anyone any ideas? i just specified the y param as 0.
05-04 20:24:08.281: ERROR/AndroidRuntime(5700): Uncaught handler: thread main exiting due to uncaught exception
05-04 20:24:08.296: ERROR/AndroidRuntime(5700): java.lang.IllegalArgumentException: y + height must be <= bitmap.height()
05-04 20:24:08.296: ERROR/AndroidRuntime(5700): at android.graphics.Bitmap.checkPixelsAccess(Bitmap.java:818)
05-04 20:24:08.296: ERROR/AndroidRuntime(5700): at android.graphics.Bitmap.getPixels(Bitmap.java:771)
05-04 20:24:08.296: ERROR/AndroidRuntime(5700): at com.tecmark.Jjilapp$TouchView.onDraw(Jjilapp.java:206)
int[] pixels = new int[myBitmap.getHeight()*myBitmap.getWidth()];
myBitmap.getPixels(pixels, 0, myBitmap.getWidth(), 0, 0, myBitmap.getHeight(), myBitmap.getWidth());
for(int i =0; i<myBitmap.getHeight()*myBitmap.getWidth();i++){
Log.e(TAG, "pixel"+i+"" +pixels[i]);
You have your width and hight switched.
myBitmap.getPixels(pixels, 0, myBitmap.getWidth(), 0, 0, myBitmap.getHeight(), myBitmap.getWidth());
vs
public void getPixels (int[] pixels, int offset, int stride, int x, int y, int width, int height)
http://developer.android.com/reference/android/graphics/Bitmap.html#getPixels(int[], int, int, int, int, int, int)
这篇关于使用的getPixels从位图获取像素()。 (抛出:IllegalArgumentException)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!