0
對不起,英語不好。我想創建一個圖像並顯示在一個片段中,當我使用editText中的OnLongClickListener()
時,片段將彈出。位圖大小超過32位editText.buildDrawingCache
,但我有一個像這樣的輸出:
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.project.testingtexttoimage, PID: 23849
java.lang.IllegalArgumentException: bitmap size exceeds 32bits
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:809)
at android.graphics.Bitmap.createBitmap(Bitmap.java:769)
at android.view.View.buildDrawingCache(View.java:13649)
at android.view.View.buildDrawingCache(View.java:13563)
at com.project.testingtexttoimage.MainActivity$1.onLongClick(MainActivity.java:31)
at android.view.View.performLongClick(View.java:4478)
at android.widget.TextView.performLongClick(TextView.java:8652)
at android.view.View$CheckForLongPress.run(View.java:18452)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)
和我的MainActivity是這樣的:
findViewById(R.id.buttonTest).setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// make image from edit text
findViewById(R.id.editTextTest).measure(
View.MeasureSpec.makeMeasureSpec(findViewById(R.id.editTextTest).getLayoutParams().width, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(findViewById(R.id.editTextTest).getLayoutParams().height, View.MeasureSpec.EXACTLY));
findViewById(R.id.editTextTest).layout(0, 0, findViewById(R.id.editTextTest).getMeasuredWidth(), findViewById(R.id.editTextTest).getMeasuredHeight());
findViewById(R.id.editTextTest).setDrawingCacheEnabled(true);
findViewById(R.id.editTextTest).buildDrawingCache();
Bitmap bmp = Bitmap.createBitmap(findViewById(R.id.editTextTest).getDrawingCache());
findViewById(R.id.editTextTest).setDrawingCacheEnabled(false);
// convert bitmap to byte array
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArrayBitmap = stream.toByteArray();
// show fragment
SupportDialogFragment fragment
= SupportDialogFragment.newInstance(
3 + 1,
1 + 2,
false,
false,
true,
false,
"Keep Trying Make Something Awesome !!!",
byteArrayBitmap
);
fragment.show(getSupportFragmentManager(), "blur_sample");
return true;
}
});
順便說一下,我用BlurFragment彈出.. THX您的幫助之前..