Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please merge #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/net/rcode/npedit/NinePatchImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ public void ensureNinePatch() {
if (isNinePatch) return;

// Otherwise, we need to add a border
BufferedImage newImage=new BufferedImage(image.getWidth()+2, image.getHeight()+2, image.getType());
BufferedImage newImage=new BufferedImage(image.getWidth()+2, image.getHeight()+2, getSafeType());
newImage.getRaster().setRect(1, 1, image.getRaster());
image=newImage;
isNinePatch=true;
}
public void ensurePlain() {

public void ensurePlain() {
if (!isNinePatch) return;

// Otherwise, we need to remove 2 rows and 2 columns
BufferedImage newImage=new BufferedImage(image.getWidth()-2, image.getHeight()-2, image.getType());
BufferedImage newImage=new BufferedImage(image.getWidth()-2, image.getHeight()-2, getSafeType());
Raster src=image.getRaster().createChild(1, 1, newImage.getWidth(), newImage.getHeight(),
0, 0, null);
newImage.getRaster().setRect(src);
Expand Down Expand Up @@ -171,7 +171,7 @@ public void expand(int targetWidth, int targetHeight) {

int[] colMarkers=getMarkers(MODE_SCALEX);
int[] rowMarkers=getMarkers(MODE_SCALEY);
BufferedImage dest=new BufferedImage(targetWidth, targetHeight, image.getType());
BufferedImage dest=new BufferedImage(targetWidth, targetHeight, getSafeType());

int colLoops=0, colRem=0;
if (colMarkers.length>0) {
Expand Down Expand Up @@ -266,4 +266,13 @@ private void copyRow(BufferedImage src, int ysrc, BufferedImage dest,
1, 0, 0, null);
dest.getRaster().setDataElements(0, ydest, srcRaster);
}

private int getSafeType() {
int type = image.getType();
if (type == BufferedImage.TYPE_CUSTOM)
// Passing BufferedImage.TYPE_CUSTOM to BufferedImage constructor will result in "java.lang.IllegalArgumentException: Unknown image type 0"
return BufferedImage.TYPE_INT_ARGB;
return type;
}

}