首页 > 编程知识 正文

安卓图片格式转换,android图片旋转代码

时间:2023-05-04 14:57:37 阅读:116787 作者:1608

我想为特定图像创建位图图像,但我想抵制位图图像的宽度和高度。 使用以下代码.

image2=bitmap factory.decode resource (get resources ),rid );

log.w(debug )、' which is null : imagei ' I.getwidth )、' OR ' i.getDrawable )、 getIntrinsicHeight );

log.w(debug )、' which is null : imageh ' h.getwidth )、' OR ' h.getHeight );

log.w(debug )、) whichisnull:image2) image2.getwidth )、(or ) image2.getheight );

bitmap image=bitmap.createscaledbitmap (image2,i.getWidth ),i.getHeight ),false );

log.w(debug )、' which is null : image ' image.getwidth )、' OR ' image.getHeight );

双精度BM width=image.getwidth (;

double bmHeight=image.getHeight (;

if (x0|| y0|) )。

返回0; //Invalid,return 0

}else{

//Convert touched x,y on View to on Bitmap

intxbm=(int ) ) x * (BM width/getwidth ) ) );

intybm=(int ) ) y * (BM height/getheight ) ) ) );

returnimage.getpixel(xbm,yBm );

但它不会给我同样的输出……它展示了我同样的宽度和高度,但我想要的输出却来不了。 在我希望的输出的高度会变大……所以,如何克服它呢? 我不能一个人提议

this.setdrawingcacheenabled (true;

//this is the important code : )

//withoutittheviewwillhaveadimensionof 0,0 andthebitmapwillbenull

this.measure (measurespec.makemeasurespec (0,MeasureSpec.UNSPECIFIED ),MeasureSpec.makeMeasureSpec(0) ) ) 0

this.layout(0,this.getMeasuredWidth ),this.getMeasuredHeight );

this.builddrawingcache(true;

bitmap image=bitmap.create bitmap (this.getdrawingcache ();

this.setdrawingcacheenabled (false;

//image2=bitmap factory.decode resource (get resource )、' which is null 3360 image2' image2.getwidth )、' or'imageer

log.w (调试)、yBm );

}

}

现在表示我的空指针异常…

堆栈跟踪

05-2915336022336007.2053: e/Android运行时(889 ) : FATAL EXCEPTION: main

05-2915336022336007.205:07 e/Android runtime (889 ) : java.lang .痴情巨人/P05-2915:2336007.20533: e/andrrr

05-2915336022336007.205:0 e/Android runtime (889 ) : atcom.example.Nam.image in.getmaskpixel (image in.javame )

05-2915336022336007.205:0 e/Android runtime (889 ) : atcom.example.Nam.ash activity.getmaskcolor ) ashactivivity

05-2915336022336007.205:0 e/Android runtime (889 ) : atcom.example.Nam.first image.page info (first image.jimage )

05-2915336022336007.205:0 e/Android runtime (889 ) : atcom.example.Nam.first image.on touch ) first image.ja

05-2915336022336007.205:0 e/Android runtime (889 ) : at Android.view.view.dispatchtouchevent (view.Java 3366666 )

05-2915336022336007.205:0 e/Android runtime (889 ) : at Android.view.viewgroup.dispatchtouchevent ) view group

05-2915336022336007.205:0 e/Android runtime (889 ) : at Android.view.viewgroup.dispatchtouchevent ) view group

05-2915336022336007.205:0 e/Android runtime (889 ) : at Android.view.viewgroup.dispatchtouchevent ) view group

05-2915336022336007.205:0 e/Android runtime (889 ) : at Android.view.viewgroup.dispatchtouchevent ) view group

05-2915336022336007.205:0 e/Android runtime (889 ) : at Android.view.viewgroup.dispatchtouchevent ) view group

05-2915336022336007.205:0 e/Android runtime (889 ) : at Android.view.viewgroup.dispatchtouchevent ) view group

05-2915336022336007.205:0 e/Android runtime (889 ) : at Android.view.viewgroup.dispatchtouchevent ) view group

05-2915336022336007.205:0 e/Android runtime (889 ) : atcom.Android.internal.policy.impl.phone window $ decod

05-2915336022336007.205:0 e/Android runtime (889 ) : atcom.Android.internal.policy.impl.phone window.suproine

05-2915336022336007.205:0 e/Android runtime (889 ) : at Android.app.activity.dispatchtouchevent (activity.jj )

05-2915336022336007.205:0 e/Android runtime (889 ) : atcom.Android.internal.policy.impl.phone window $ decod

05-2915336022336007.205:0 e/Android runtime (889 ) : at Android.view.view root.handle message ) viewroot.Java360

05-2915336022336007.205:0 e/Android runtime (889 ) : at Android.OS.handler.dispatch message (handler.Java 333336 )

05-2915336022336007.205: e/Android运行时(889 ) : at Android.OS.looper.loop (looper.Java 3360123 ) ) )

05-2915336022336007.205:0 e/Android runtime (889 ) : at Android.app.activity thread.main (activity thread.javave )

05-2915336022336007.205:0 e/Android runtime (889 ) : at Java.lang.reflect.method.invoke native ) nativemethod

05-2915336022336007.205:0 e/Android runtime (889 ) : at Java.lang.reflect.method.invoke ) method.Java336000

05-2915336022336007.205:0 e/Android runtime (889 ) : atcom.Android.internal.OS.zygote init $ methodandargscard

05-2915336022336007.205:0 e/Android runtime (889 ) : atcom.Android.internal.OS.zygote init.main ) zygoteinnin

05-2915336022336007.205:0 e/Android runtime (889 ) : atdalvik.system.native start.main (native method ) ) ) )

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。