-
Notifications
You must be signed in to change notification settings - Fork 154
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
updated by GinforJM #91
base: master
Are you sure you want to change the base?
Conversation
the issue 81 has been solved. I will preprocess the background image and change it to be transparent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GinforJM 谢谢你支持KUMO!我评论了一些小的推荐和请求。
我觉得第一重要的应该是那个“sun.font.FontDesignMetrics”的class。因为这个class从sun(oracle)的package来的,所以好像不能用,因为有很大的可能别的JDK就没有这个package,所以就不能compile。我还没想到最好的办法解决这个。最坏情况是我们可以直接把那个class拷贝到KUMO里。我们先去研究一下。
如果还有什么不清楚的地方,马上跟我说,谢谢:)。
/** | ||
* preprocess the image if the image is not | ||
*/ | ||
//CS304 Issue link: https://github.com/kennycason/kumo/issues/81 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go ahead and remove the line 38 comments.
@Override | ||
public void mask(final RectanglePixelCollidable background) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intentionally want final
on all variables and method parameters. It's considered best practice and most programming languages now include val/var
types as first level types as well with preference on val
, including new versions of Java.
import com.kennycason.kumo.collide.RectanglePixelCollidable; | ||
import com.kennycason.kumo.image.CollisionRaster; | ||
|
||
import sun.font.FontDesignMetrics; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you find another way to implement this without using sun.*
package. In general, usage of sun.*
packages have been deprecated for some time if I recall correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://stackoverflow.com/questions/8565708/what-is-inside-com-sun-package
Check out the top rated answer for more details:
Please note that the
com.sun.*
package should not be confused withsun.*
package which are the internal classes behind Oracle JRE which you should absolutely not import/use in your code as it would make your code tight coupled to the JRE make/version. Not usingsun.*
package at all enables you to run your code on all other JRE implementations (OpenJDK, GCJ, etc).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll also research a better alternative. If you can't find another alternative, feel free to literally just copy the implementation into Kumo if it is small enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GinforJM Hi! I just wanted to check back in and see if you found an alternative to sun.font.FontDesignMetrics
.
Thanks!
* @param size the size of each character in the string | ||
*/ | ||
//CS304 Issue link: https://github.com/kennycason/kumo/issues/70 | ||
public PixelBoundryBackground(String example , int size){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final variables/parameters. (and space between ) {
)
* @param content the content of the input string | ||
* @return return a width of a word | ||
*/ | ||
//CS304 Issue link: https://github.com/kennycason/kumo/issues/70 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove comment on line 137.
graphics.drawString(example, 0, metrics.getAscent());//图片上写文字 | ||
graphics.dispose(); | ||
BufferedImage b = preprocess(bufferedImage,5); | ||
// changed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete this comment on line 125.
*/ | ||
//CS304 Issue link: https://github.com/kennycason/kumo/issues/70 | ||
public PixelBoundryBackground(String example , int size){ | ||
Font font = new Font("微软雅黑", Font.BOLD, size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should make this:
-
rename
example
totext
-
final Font font = new Font(settings.getFontName(), settings.getFontWeight(), settings.getFontSize());
This way we can configure the font and we should also come up with a better default font. I don't think most people are familiar with "微软雅黑". MaybeCalibri
for now, or something else more common.
Then where you useexample
below, you can also just saysettings.getText()
you could then construct with PixelBoundryBackground(final PixelBoundryBackgroundSettings settings)
} | ||
BufferedImage bi = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_4BYTE_ABGR);//Create a new type that supports transparent BufferedImage | ||
for(int i = 0; i < imgWidth; ++i)//Copy the contents of the original image to the new image, and set the background to transparent | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put the brackets on the same same line as for, also note spacing/finals.
for (int i = 0; i < imgWidth; ++i) {
Apply to all below code.
int imgWidth = srcImage.getWidth(); | ||
int c = srcImage.getRGB(3, 3); | ||
//防止越位 | ||
if (alpha < 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel we should set alpha value between [0.0, 1.0], and if the users sets it over < 0.0 or > 1.0, throw an exception since it's bad input. Then later you can more easily do: rgb = ((alpha * 255).toInt() << 24) | (rgb & 0x00ffffff);
below.
Thanks for your reply and Suggestions!
I will read your Suggestions carefully and take time to figure out if I can solve them.
…------------------ 原始邮件 ------------------
发件人: "Kenny Cason"<[email protected]>;
发送时间: 2020年6月23日(星期二) 凌晨4:03
收件人: "kennycason/kumo"<[email protected]>;
抄送: "1452044324"<[email protected]>;"Mention"<[email protected]>;
主题: Re: [kennycason/kumo] updated by GinforJM (#91)
@kennycason requested changes on this pull request.
@GinforJM 谢谢你支持KUMO!我评论了一些小的推荐和请求。
我觉得第一重要的应该是那个“sun.font.FontDesignMetrics”的class。因为这个class从sun(oracle)的package来的,所以好像不能用,因为有很大的可能别的JDK就没有这个package,所以就不能compile。我还没想到最好的办法解决这个。最坏情况是我们可以直接把那个class拷贝到KUMO里。我们先去研究一下。
如果还有什么不清楚的地方,马上跟我说,谢谢:)。
In kumo-core/src/main/java/com/kennycason/kumo/bg/PixelBoundaryBackground.java:
> final BufferedImage bufferedImage = ImageIO.read(imageInputStream); - this.collisionRaster = new CollisionRaster(bufferedImage); + /** + * preprocess the image if the image is not + */ + //CS304 Issue link: #81
go ahead and remove the line 38 comments.
In kumo-core/src/main/java/com/kennycason/kumo/bg/PixelBoundaryBackground.java:
> @OverRide - public void mask(final RectanglePixelCollidable background) {
I intentionally want final on all variables and method parameters. It's considered best practice and most programming languages now include val/var types as first level types as well with preference on val, including new versions of Java.
In kumo-core/src/main/java/com/kennycason/kumo/bg/PixelBoundaryBackground.java:
> import com.kennycason.kumo.collide.RectanglePixelCollidable; import com.kennycason.kumo.image.CollisionRaster; - +import sun.font.FontDesignMetrics;
Can you find another way to implement this without using sun.* package. In general, usage of sun.* packages have been deprecated for some time if I recall correctly.
In kumo-core/src/main/java/com/kennycason/kumo/bg/PixelBoundaryBackground.java:
> this(new File(filepath)); } - + + /** + *Creates a PixelBoundaryBackground using an image-path + * + * @param example a string which you want to use to be a background + * @param size the size of each character in the string + */ + //CS304 Issue link: #70 + public PixelBoundryBackground(String example , int size){
final variables/parameters. (and space between ) {)
In kumo-core/src/main/java/com/kennycason/kumo/bg/PixelBoundaryBackground.java:
> import com.kennycason.kumo.collide.RectanglePixelCollidable; import com.kennycason.kumo.image.CollisionRaster; - +import sun.font.FontDesignMetrics;
https://stackoverflow.com/questions/8565708/what-is-inside-com-sun-package
Check out the top rated answer for more details:
Please note that the com.sun.* package should not be confused with sun.* package which are the internal classes behind Oracle JRE which you should absolutely not import/use in your code as it would make your code tight coupled to the JRE make/version. Not using sun.* package at all enables you to run your code on all other JRE implementations (OpenJDK, GCJ, etc).
In kumo-core/src/main/java/com/kennycason/kumo/bg/PixelBoundaryBackground.java:
> import com.kennycason.kumo.collide.RectanglePixelCollidable; import com.kennycason.kumo.image.CollisionRaster; - +import sun.font.FontDesignMetrics;
I'll also research a better alternative. If you can't find another alternative, feel free to literally just copy the implementation into Kumo if it is small enough.
In kumo-core/src/main/java/com/kennycason/kumo/bg/PixelBoundaryBackground.java:
> + graphics.drawString(example, 0, metrics.getAscent());//图片上写文字 + graphics.dispose(); + BufferedImage b = preprocess(bufferedImage,5); + // changed + this.collisionRaster = new CollisionRaster(b); + // this.collisionRaster = new CollisionRaster(bufferedImage); + // write(bufferedImage, "D:\\Gin_app\\IDEA\\kumocore\\test.jpg"); + } + + /** + * + * @param font the font of each character + * @param content the content of the input string + * @return return a width of a word + */ + //CS304 Issue link: #70
remove comment on line 137.
In kumo-core/src/main/java/com/kennycason/kumo/bg/PixelBoundaryBackground.java:
> + FontDesignMetrics metrics = FontDesignMetrics.getMetrics(font); + int width = getWordWidth(font, example); + int height = metrics.getHeight(); + BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + Graphics2D graphics = bufferedImage.createGraphics(); + graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); + //Set the back to white + graphics.setColor(Color.WHITE); + graphics.fillRect(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight()); + graphics.setFont(font); + graphics.setColor(Color.BLACK); + graphics.drawString(example, 0, metrics.getAscent());//图片上写文字 + graphics.dispose(); + BufferedImage b = preprocess(bufferedImage,5); + // changed
delete this comment on line 125.
In kumo-core/src/main/java/com/kennycason/kumo/bg/PixelBoundaryBackground.java:
> this(new File(filepath)); } - + + /** + *Creates a PixelBoundaryBackground using an image-path + * + * @param example a string which you want to use to be a background + * @param size the size of each character in the string + */ + //CS304 Issue link: #70 + public PixelBoundryBackground(String example , int size){ + Font font = new Font("微软雅黑", Font.BOLD, size);
I think we should make this:
rename example to text
final Font font = new Font(settings.getFontName(), settings.getFontWeight(), settings.getFontSize());
This way we can configure the font and we should also come up with a better default font. I don't think most people are familiar with "微软雅黑". Maybe Calibri for now, or something else more common.
Then where you use example below, you can also just say settings.getText()
you could then construct with PixelBoundryBackground(final PixelBoundryBackgroundSettings settings)
In kumo-core/src/main/java/com/kennycason/kumo/bg/PixelBoundaryBackground.java:
> + * @return we will return a bufferedimage object which has been preprocessed + */ + //CS304 Issue link: #81 + private BufferedImage preprocess(BufferedImage srcImage,int alpha) { + int imgHeight = srcImage.getHeight();//取得图片的长和宽 + int imgWidth = srcImage.getWidth(); + int c = srcImage.getRGB(3, 3); + //防止越位 + if (alpha < 0) { + alpha = 0; + } else if (alpha > 10) { + alpha = 10; + } + BufferedImage bi = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_4BYTE_ABGR);//Create a new type that supports transparent BufferedImage + for(int i = 0; i < imgWidth; ++i)//Copy the contents of the original image to the new image, and set the background to transparent + {
put the brackets on the same same line as for, also note spacing/finals.
for (int i = 0; i < imgWidth; ++i) {
Apply to all below code.
In kumo-core/src/main/java/com/kennycason/kumo/bg/PixelBoundaryBackground.java:
> + this.collisionRaster = new CollisionRaster(b); + } + + /** + * + * @param srcImage srcImage will be preprocessed , the method will set the background to be transparent + * @param alpha alpha is a transparency + * @return we will return a bufferedimage object which has been preprocessed + */ + //CS304 Issue link: #81 + private BufferedImage preprocess(BufferedImage srcImage,int alpha) { + int imgHeight = srcImage.getHeight();//取得图片的长和宽 + int imgWidth = srcImage.getWidth(); + int c = srcImage.getRGB(3, 3); + //防止越位 + if (alpha < 0) {
I feel we should set alpha value between [0.0, 1.0], and if the users sets it over < 0.0 or > 1.0, throw an exception since it's bad input. Then later you can more easily do: rgb = ((alpha * 255).toInt() << 24) | (rgb & 0x00ffffff); below.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
the issue 81 has been solved.
I will preprocess the background image and change it to be transparent.