Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
XChart
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Brady James Garvin
XChart
Commits
78aaec5c
Commit
78aaec5c
authored
10 years ago
by
Chiamh
Browse files
Options
Downloads
Patches
Plain Diff
avoid duplicate file extensions
parent
73d5bf1a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
xchart/src/main/java/com/xeiam/xchart/BitmapEncoder.java
+22
-4
22 additions, 4 deletions
xchart/src/main/java/com/xeiam/xchart/BitmapEncoder.java
xchart/src/main/java/com/xeiam/xchart/XChartPanel.java
+1
-1
1 addition, 1 deletion
xchart/src/main/java/com/xeiam/xchart/XChartPanel.java
with
23 additions
and
5 deletions
xchart/src/main/java/com/xeiam/xchart/BitmapEncoder.java
+
22
−
4
View file @
78aaec5c
...
...
@@ -54,6 +54,23 @@ public final class BitmapEncoder {
PNG
,
JPG
,
BMP
,
GIF
;
}
/**
* Only adds the extension of the BitmapFormat to the filename if the filename doesn't already have it.
*
* @param fileName
* @param bitmapFormat
* @return filename (if extension already exists), otherwise;: filename + "." + extension
*/
private
static
String
addFileExtension
(
String
fileName
,
BitmapFormat
bitmapFormat
)
{
String
fileNameWithFileExtension
=
fileName
;
final
String
newFileExtension
=
"."
+
bitmapFormat
.
toString
().
toLowerCase
();
if
(
fileName
.
length
()
<=
newFileExtension
.
length
()
||
!
fileName
.
substring
(
fileName
.
length
()-
newFileExtension
.
length
(),
fileName
.
length
()).
equalsIgnoreCase
(
newFileExtension
))
{
fileNameWithFileExtension
=
fileName
+
newFileExtension
;
}
return
fileNameWithFileExtension
;
}
/**
* Save a Chart as an image file
*
...
...
@@ -66,7 +83,7 @@ public final class BitmapEncoder {
BufferedImage
bufferedImage
=
getBufferedImage
(
chart
);
OutputStream
out
=
new
FileOutputStream
(
fileName
+
"."
+
bitmapFormat
.
toString
().
toLowerCase
(
));
OutputStream
out
=
new
FileOutputStream
(
addFileExtension
(
fileName
,
bitmapFormat
));
ImageIO
.
write
(
bufferedImage
,
bitmapFormat
.
toString
().
toLowerCase
(),
out
);
out
.
close
();
}
...
...
@@ -108,7 +125,7 @@ public final class BitmapEncoder {
setDPI
(
metadata
,
DPI
);
File
file
=
new
File
(
fileName
+
"."
+
bitmapFormat
.
toString
().
toLowerCase
(
));
File
file
=
new
File
(
addFileExtension
(
fileName
,
bitmapFormat
));
FileImageOutputStream
output
=
new
FileImageOutputStream
(
file
);
writer
.
setOutput
(
output
);
IIOImage
image
=
new
IIOImage
(
bufferedImage
,
null
,
metadata
);
...
...
@@ -150,11 +167,12 @@ public final class BitmapEncoder {
*
* @param chart
* @param fileName
* @param bitmapFormat
* @param quality - a float between 0 and 1 (1 = maximum quality)
* @throws FileNotFoundException
* @throws IOException
*/
public
static
void
saveJPGWithQuality
(
Chart
chart
,
String
fileName
,
float
quality
)
throws
FileNotFoundException
,
IOException
{
public
static
void
saveJPGWithQuality
(
Chart
chart
,
String
fileName
,
BitmapFormat
bitmapFormat
,
float
quality
)
throws
FileNotFoundException
,
IOException
{
BufferedImage
bufferedImage
=
getBufferedImage
(
chart
);
...
...
@@ -164,7 +182,7 @@ public final class BitmapEncoder {
ImageWriteParam
iwp
=
writer
.
getDefaultWriteParam
();
iwp
.
setCompressionMode
(
ImageWriteParam
.
MODE_EXPLICIT
);
iwp
.
setCompressionQuality
(
quality
);
File
file
=
new
File
(
fileName
);
File
file
=
new
File
(
addFileExtension
(
fileName
,
bitmapFormat
)
);
FileImageOutputStream
output
=
new
FileImageOutputStream
(
file
);
try
{
writer
.
setOutput
(
output
);
...
...
This diff is collapsed.
Click to expand it.
xchart/src/main/java/com/xeiam/xchart/XChartPanel.java
+
1
−
1
View file @
78aaec5c
...
...
@@ -130,7 +130,7 @@ public class XChartPanel extends JPanel {
if
(
fileChooser
.
getFileFilter
()
==
null
)
{
BitmapEncoder
.
saveBitmap
(
chart
,
theFileToSave
.
getCanonicalPath
().
toString
(),
BitmapFormat
.
PNG
);
}
else
if
(
fileChooser
.
getFileFilter
().
getDescription
().
equals
(
"*.jpg,*.JPG"
))
{
BitmapEncoder
.
saveJPGWithQuality
(
chart
,
theFileToSave
.
getCanonicalPath
().
toString
()
+
".jpg"
,
1.0f
);
BitmapEncoder
.
saveJPGWithQuality
(
chart
,
theFileToSave
.
getCanonicalPath
().
toString
()
,
BitmapFormat
.
JPG
,
1.0f
);
}
else
if
(
fileChooser
.
getFileFilter
().
getDescription
().
equals
(
"*.png,*.PNG"
))
{
BitmapEncoder
.
saveBitmap
(
chart
,
theFileToSave
.
getCanonicalPath
().
toString
(),
BitmapFormat
.
PNG
);
}
else
if
(
fileChooser
.
getFileFilter
().
getDescription
().
equals
(
"*.bmp,*.BMP"
))
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment