graphics device is null
时间: 2024-06-03 17:08:21 浏览: 166
As an AI language model, I cannot provide a specific answer without additional information. However, in general, the error message "graphics device is null" typically occurs in programming when attempting to access a graphics device that has not been initialized or has been closed. This error message may also occur if the graphics driver is outdated or incompatible with the system. To resolve this issue, ensure that the graphics device is properly initialized and updated.
相关问题
Error in .Call.graphics(C_palette2, .Call(C_palette2, NULL)) : invalid graphics state
This error message typically occurs when there is a problem with the graphics device or when the graphics state is not properly initialized.
Here are some steps you can try to resolve the issue:
1. Restart R and try running the code again.
2. Check if there are any open graphics devices using the `dev.list()` function. If there are, close them using `dev.off()`.
3. Make sure you have the latest version of R and all packages you are using. You can check for updates using the `update.packages()` function.
4. Try changing the graphics device using the `pdf()`, `png()`, or `jpeg()` functions.
5. Try resetting the graphics device using the `graphics.off()` function.
6. If none of the above steps work, try running the code on a different computer or operating system.
If you continue to experience problems, you may want to seek help from the R community or the package developer.
/packages/apps/Launcher3/src/com/android/launcher3/graphics/IconShapeOverride.java源码
以下是 IconShapeOverride.java 的源代码:
```java
package com.android.launcher3.graphics;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Path;
import android.graphics.Rect;
import android.os.Build;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.android.launcher3.Utilities;
import com.android.launcher3.icons.GraphicsUtils;
import com.android.launcher3.icons.IconProvider;
import com.android.launcher3.icons.ShapeData;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.util.ResourceBasedOverride;
/**
* Provides custom icon shapes based on user preferences.
*/
public class IconShapeOverride extends ResourceBasedOverride {
public static final String KEY_PREFERENCE = "pref_override_icon_shape";
private static final String TAG = "IconShapeOverride";
private final IconProvider mIconProvider;
public IconShapeOverride(Context context) {
this(context, IconProvider.INSTANCE);
}
@VisibleForTesting
public IconShapeOverride(Context context, IconProvider iconProvider) {
super(context, KEY_PREFERENCE);
mIconProvider = iconProvider;
}
/**
* @return the current shape path, or null if not defined.
*/
@Nullable
public ShapeData getShape() {
String pathString = getStringValue();
if (pathString == null) {
return null;
}
try {
return ShapeData.parse(pathString);
} catch (IllegalArgumentException e) {
Log.e(TAG, "Unable to parse shape", e);
return null;
}
}
/**
* @return the current shape path as a {@link Path} instance, or null if not defined.
*/
@Nullable
public Path getShapePath() {
ShapeData data = getShape();
return data != null ? data.getPath() : null;
}
/**
* @return the current shape path bounds, or null if not defined.
*/
@Nullable
public Rect getShapeBounds() {
ShapeData data = getShape();
return data != null ? data.getBounds() : null;
}
/**
* Returns the shape path for the given context, or null if none is specified.
*/
public static Path getShapePath(Resources res, SharedPreferences prefs) {
IconShapeOverride override = new IconShapeOverride(res);
override.setSharedPreferences(prefs);
return override.getShapePath();
}
/**
* Tests whether the current shape is a circle, by checking if all corners of the shape are at
* the same distance from the center.
*/
public boolean isShapeCircle() {
Path shape = getShapePath();
if (shape == null) {
return false;
}
Rect bounds = getShapeBounds();
if (bounds == null) {
return false;
}
Rect outBounds = new Rect();
shape.computeBounds(outBounds, true);
float centerX = bounds.exactCenterX();
float centerY = bounds.exactCenterY();
float radius = Math.max(centerX - bounds.left, centerY - bounds.top);
float maxDeviation = 0;
float[] radii = new float[9];
shape.approximate(1f, radii);
for (int i = 0; i < radii.length; i += 2) {
float deviation = Math.abs(radii[i] - radius);
if (deviation > maxDeviation) {
maxDeviation = deviation;
}
}
return maxDeviation < GraphicsUtils.EPSILON;
}
/**
* Updates the default icon shape, if the user has not overridden it.
*/
public static void updateDefaultShape(Context context) {
SharedPreferences prefs = Utilities.getPrefs(context);
if (prefs.contains(KEY_PREFERENCE)) {
return;
}
IconShapeOverride override = new IconShapeOverride(context);
Path path = override.getDefaultShape();
if (path != null) {
prefs.edit().putString(KEY_PREFERENCE, ShapeData.toString(path)).apply();
}
}
/**
* @return the default shape path for the current device.
*/
@Nullable
public Path getDefaultShape() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return IconShape.applyMaskIfNeeded(mIconProvider.getDeviceProfile(),
mIconProvider.getIconMask());
}
return null;
}
@Override
protected void onValueChanged() {
super.onValueChanged();
mIconProvider.clearCaches();
}
}
```
该类提供了自定义应用图标的形状的功能,它会根据用户的偏好设置提供自定义图标形状。其中包含了获取、设置、更新默认图标形状等方法。此外,还包含一些辅助方法,如测试当前形状是否为圆形。在 Android Oreo 及以上版本中,会调用 IconShape 类提供的方法来获取默认图标形状。
阅读全文