gpt4 book ai didi

android - 尝试从 View 中获取位图时总是出现 IllegalStateException 错误

转载 作者:行者123 更新时间:2023-11-29 01:04:12 26 4
gpt4 key购买 nike

我正在尝试从 GraphView 获取位图,以免生成两次相同的图形。我不断收到以下错误(尽管 hardwareAccelerated=true):

java.lang.IllegalStateException: GraphView must be used in hardware accelerated mode.You can use android:hardwareAccelerated="true" on your activity

-这是我尝试执行此操作的代码:

ImageView imageView = (ImageView) convertView.findViewById(R.id.imageView);
Bitmap bitmap = Bitmap.createBitmap(graphView.getWidth(), graphView.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Drawable bgDrawable = graphView.getBackground();
if (bgDrawable != null) {
bgDrawable.draw(canvas);
} else {
canvas.drawColor(Color.BLUE);
}

graphView.draw(canvas);
imageView.setImageBitmap(bitmap);

我试过很多东西,但没有一个成功。我什至尝试将 graphView 放在布局中并从布局中获取位图,但这也没有用(我得到完全相同的错误)。

如有任何帮助,我们将不胜感激!

最佳答案

试试这个:

Bitmap bitmap = Bitmap.createBitmap(graphView.getWidth(),graphView.getHeight(),Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap){

@Override
public boolean isHardwareAccelerated(){
return true;
}
};

graphView.draw(canvas);
imageView.setImageBitmap(bitmap);

关于android - 尝试从 View 中获取位图时总是出现 IllegalStateException 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48709659/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com