I am developing an rsps and cant seem to find where to find the background image
i found the loading screen but cant find the background image any ideas on what to search?
loading screen code
try {
for (int i = 1; i <= 3; i++) {
if (!new File(signlink.findcachedir() + "load" + i + ".png").exists()) {
String url = "";
switch (i) {
case 1:
url = "http://Morytania.org/load1.png";
break;
case 2:
url = "http://Morytania.org/load2.png";
break;
case 3:
url = "http://Morytania.org/load3.png";
break;
}
HttpDownloadUtility.downloadFile(url, signlink.findcachedir());
}
loadingSprites[i - 1] = Toolkit.getDefaultToolkit()
.getImage(signlink.findcachedir() + "load" + i + ".png");
}
super.graphics.drawImage(loadingSprites[0], 0, 0, null);
super.graphics.drawImage(loadingSprites[1], 5, clientHeight - 35, null);
} catch (Exception e) {
e.printStackTrace();
}
It would appear that you're using revision 317 of the RuneScape client. In the older versions of the engine, such as the one you're using, the background is, by default, loaded from the game cache.
Inside of archive 0, there is a file labelled "title". Inside of that file, you may find the actual background ("title.dat") as the login box ("titlebox.dat") and buttons ("titlebutton.dat"). These files are simply JPEG images.
The background itself is stored as a 383x503 image that is then mirrored in-engine to create the full image. See createTitleBackground(). An excerpt of the code can be found below.
public void createTitleBackground() throws IOException {
Image24 image = new Image24(archiveTitle.read("title.dat"), this);
...
// Flips the title background horizontally
int[] tmp = new int[image.width];
for (int y = 0; y < image.height; y++) {
for (int x = 0; x < image.width; x++) {
tmp[x] = image.pixels[(image.width - x - 1) + (image.width * y)];
}
System.arraycopy(tmp, 0, image.pixels, image.width * y, image.width);
}
...
}
The code above is then called in the load() method:
archiveTitle = loadArchive(1, "title screen", "title", archiveChecksum[1], 25);
fontPlain11 = new BitmapFont(archiveTitle, "p11_full", false);
fontPlain12 = new BitmapFont(archiveTitle, "p12_full", false);
fontBold12 = new BitmapFont(archiveTitle, "b12_full", false);
fontQuill8 = new BitmapFont(archiveTitle, "q8_full", true);
createTitleBackground();
createTitleImages();
Related
I'm trying to show a JProgressBar in a Swing application used for communicating with a device using a SerialPort connection.
Sometimes the data that the device sends is large so it can take some time(5-10 seconds) to receive the data. Because of that, I want to show the user a progress bar so he knows that something is happening.
I tried doing this with JProgressBar and also with ProgressMonitor, but I just managed to show the progress window, but it just stayed at 0%.
Here is a method that I use to read the serialPort.
public static void readingDataSB9(SerialPort comPort) {
comPort.addDataListener(new SerialPortDataListener() {
#Override
public int getListeningEvents() {
return SerialPort.LISTENING_EVENT_DATA_AVAILABLE;
}
#Override
public void serialEvent(SerialPortEvent serialPortEvent) {
try {
if (serialPortEvent.getEventType() != SerialPort.LISTENING_EVENT_DATA_AVAILABLE) {
return;
}
//here I save the count data in the string array
List<String> countData = new ArrayList<>();
//here I save the text that is OCRed from the images
List<String> ocrText = new ArrayList<>();
//here I save the images from the machine
List<ImageIcon> serialImage = new ArrayList<>();
//trying to decode non UTF-8 strings from an array of Strings, only for TEST purposes
CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder();
decoder.onMalformedInput(CodingErrorAction.IGNORE);
//Strings that represent the start of the serial number and new lines on each serial number
String startSn = "110000010011010001101100100011011000100011010000111000010001010";
String newLine = "01100000110110010001101100010001101000011100001000101";
int x = 0;
String s1 = "";
//getting InputStream from serial port and then converting it to BufferedStream, so it can be reset
//and read two times
InputStream in = comPort.getInputStream();
InputStream bufferdInputStream = new BufferedInputStream(in);
bufferdInputStream.mark(1000000000);
//I try to show progress of receiving data from InputStream
showProgress(bufferdInputStream, MainWindow.frame);
//first reading the input stream with scanner to get count data as Strings
Scanner sc = new Scanner(bufferdInputStream);
while (sc.hasNextLine()) {
countData.add(sc.next());
//this is the last string in the InputStream, so I use it to break from the while loop
if (countData.contains("\u001Bm\u001B3")) {
break;
}
}
System.out.println(countData);
//here I reset the InputStream, so it can be read again to receive the bytes needed to get the image
//of serial number
bufferdInputStream.reset();
while (((x = bufferdInputStream.read()) != 109)) {
//bytes are converted to binaryStrings, so I can get the binary image with Java Graphics library
s1 += String.format("%8s", Integer.toBinaryString(x & 0xFF)).replace(' ', '0');
}
//bytes are stored in the String array, they are split by String for the start of serial number
String[] binarySerialNumberArr = s1.split(startSn);
//here I immediately write the binaryString to the gui of MainWindow, so it can be saved to the database
MainWindow.jt_serialBinary.setText(String.join(", ", binarySerialNumberArr));
//here we take each element of String array and convert it from BinaryString to image
for (int i = 1; i < binarySerialNumberArr.length; i++) {
//first we create a empty image
BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = img.createGraphics();
Font font = new Font("Arial", Font.PLAIN, 2);
g2d.setFont(font);
int height = g2d.getFontMetrics().getHeight();
g2d.dispose();
//here we start to create the actual image of the serial number
img = new BufferedImage(384, 40, BufferedImage.TYPE_INT_RGB);
g2d = img.createGraphics();
g2d.setFont(font);
g2d.setColor(Color.WHITE);
int fontSize = 1;
for (String s : binarySerialNumberArr[i].split(newLine)) {
//we draw each string and use the newLine String to split the array element
//each 0 is represented as white, and 1 as black
g2d.drawString(s, 0, height);
height += fontSize;
}
//creating the image file
File file = new File("images\\Text" + i + ".png");
//saving the image to file
ImageIO.write(img, "png", file);
g2d.dispose();
//here we use the Tesseracts OCR library to get OCR text from image file
String ocrString = SerialOcr(file);
//here we fix some mistakes that OCR library does when doing OCR on images and add the data to
//OCR string array
ocrText.add(trainOcr(ocrString));
//we convert to image to ImageIcon and add it to ImageIcon array
serialImage.add(makeIcon(img));
System.out.println(ocrString);
}
//here we add ocrText to gui MainWindow
for (int i = 0; i < ocrText.size(); i++) {
MainWindow.model_ocrText.add(i, ocrText.get(i));
}
//here we add images to gui MainWindow
for (int i = 0; i < serialImage.size(); i++) {
MainWindow.model_serialImage.add(i, serialImage.get(i));
}
//here I try to ignore non UTF-8 string so I can get the OCR values from the machine also
//this is a TEST
ArrayList<String> validData = new ArrayList<>();
for (int i = 0; i < countData.size(); i++) {
decoder.decode(java.nio.ByteBuffer.wrap(countData.get(i).getBytes()));
validData.add(countData.get(i));
}
System.out.println(validData);
//checking to see what currency is the data from the machine, and building the gui table accordingly
for (int i = 0; i < countData.size(); i++) {
switch (countData.get(i)) {
case "RSD" -> insertRSD(countData, MainWindow.jt_denom);
case "USD" -> insertUSD(countData, MainWindow.jt_denom);
case "EUR" -> insertEUR(countData, MainWindow.jt_denom);
default ->
//in case none of the above currencies is chosen, we show the error message on JOptionPane
JOptionPane.showMessageDialog(null, "Odabrana valuta nije podržana", "Greška!", JOptionPane.ERROR_MESSAGE);
}
}
//after getting all the data to the gui table in MainWindow, we calculate the total count data
ButtonListeners.tableTotalAmountRows(MainWindow.jt_denom);
ButtonListeners.tableTotalAmountColumns(MainWindow.jt_denom);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
Here is the showProgress method.
public static void showProgress(InputStream bufferedInputStream, JFrame frame) throws IOException {
JOptionPane pane = new JOptionPane();
pane.setMessage("Receiving data...");
JProgressBar jProgressBar = new JProgressBar(1, bufferedInputStream.available());
jProgressBar.setValue(bufferedInputStream.read());
pane.add(jProgressBar,1);
JDialog dialog = pane.createDialog(frame, "Information message");
dialog.setVisible(true);
dialog.dispose();
}
If someone has a better idea of how to show the progress, or just to keep the message on the screen while the data is being received, please feel free to suggest it.
Thanks in advance
I have a very long string which may be continuous without space or not continuous, and it should automatically generate pdf with with multiple pages if necessary and with proper multiline with PdfDocument.
I have tried firstly using paint but only one line with text overflowing was being printed. This problem was solved using StaticLayout and proper multiline is got but now the text gets overflown from below.
I have searched a lot but didn't exactly find one and I don't want to use iText as its only for opensource projects.
This solution by which I solved the problem by using simple PdfDocument and StaticLayout without using any external paid libraries. The problem as I have shared in my question is that maintaining proper structure of the texts in the generated pdf file.
I used the length and width of a A4 size page and have fixed the number of characters in each page to a limit, after that when it encounters the end of that line it automatically creates next page, also auto next line is handled by StaticLayout no overflowing of text is seen.
If you feel you can try with different character limit for each page and try different size as your need. Also you can try the StaticLayout.Builder which is supported in Android version Q/29 and above not below it.
The code sample I will share with you, which if you use, no matter how long the text you have, it will automatically handle multi page if text is long and generate the pdf, also it maintains paragraphs etc, you can also customise page shape, number of characters etc according to your need. Other details in the code are self-explanatory.
String text = "Lorem ipsum...very long text";
ArrayList<String> texts = new ArrayList<>();
int tot_char_count = 0;
//Counts total characters in the long text
for (int i = 0; i < text.length(); i++) {
tot_char_count++;
}
int per_page_words = 4900;
int pages = tot_char_count / per_page_words;
int remainder_pages_extra = tot_char_count % per_page_words;
if (remainder_pages_extra > 0) {
pages++;
}
int k = pages, count = 0;
while (k != 0) {
StringBuilder each_page_text = new StringBuilder();
for (int y = 0; y < per_page_words; y++) {
if (count < tot_char_count) {
each_page_text.append(text.charAt(count));
if (y == (per_page_words - 1) && text.charAt(count) != ' ') {
while (text.charAt(count) != '\n') {
count++;
each_page_text.append(text.charAt(count));
}
} else {
count++;
}
}
}
texts.add(each_page_text.toString());
k--;
}
PdfDocument pdfDocument = new PdfDocument();
int pageNumber = 0;
try {
pageNumber++;
for (String each_page_text : texts) {
PdfDocument.PageInfo mypageInfo = new PdfDocument.PageInfo.Builder(595, 842, pageNumber).create();
PdfDocument.Page myPage = pdfDocument.startPage(mypageInfo);
Canvas canvas = myPage.getCanvas();
TextPaint mTextPaint = new TextPaint();
mTextPaint.setTextSize(11);
mTextPaint.setTypeface(ResourcesCompat.getFont(context, R.font.roboto));
StaticLayout mTextLayout = new StaticLayout(each_page_text, mTextPaint, canvas.getWidth() - 60, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
canvas.save();
int textX = 30;
int textY = 30;
canvas.translate(textX, textY);
mTextLayout.draw(canvas);
canvas.restore();
pdfDocument.finishPage(myPage);
}
File file = new File(context.getFilesDir(), "GeneratedFile.pdf");
FileOutputStream fOut = new FileOutputStream(file);
pdfDocument.writeTo(fOut);
// Toast.makeText(context, "PDF file generated successfully.", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
pdfDocument.close();
I need to try these code for when running this code after 5 seconds then will jump to another function. How i can combine, is using thread?
private Mat get_template(CascadeClassifier clasificator, Rect area,int size){
Mat template = new Mat();
Mat mROI = mGray.submat(area);
MatOfRect eyes = new MatOfRect();
Point iris = new Point();
Rect eye_template = new Rect();
clasificator.detectMultiScale(mROI, eyes, 1.15, 2,Objdetect.CASCADE_FIND_BIGGEST_OBJECT|Objdetect.CASCADE_SCALE_IMAGE, new Size(30,30),new Size());
Rect[] eyesArray = eyes.toArray();
for (int i = 0; i < eyesArray.length; i++){
Rect e = eyesArray[i];
e.x = area.x + e.x;
e.y = area.y + e.y;
Rect eye_only_rectangle = new Rect((int)e.tl().x,(int)( e.tl().y + e.height*0.4),(int)e.width,(int)(e.height*0.6));
// reduce ROI
mROI = mGray.submat(eye_only_rectangle);
Mat vyrez = mRgba.submat(eye_only_rectangle);
// find the darkness point
Core.MinMaxLocResult mmG = Core.minMaxLoc(mROI);
// draw point to visualise pupil
Core.circle(vyrez, mmG.minLoc,2, new Scalar(255, 255, 255, 255),2);
iris.x = mmG.minLoc.x + eye_only_rectangle.x;
iris.y = mmG.minLoc.y + eye_only_rectangle.y;
eye_template = new Rect((int)iris.x-size/2,(int)iris.y-size/2 ,size,size);
Core.rectangle(mRgba,eye_template.tl(),eye_template.br(),new Scalar(255, 0, 0, 255), 2);
// copy area to template
template = (mGray.submat(eye_template)).clone();
return template;
}
return template;
}
Resource from: http://romanhosek.cz/android-eye-detection-and-tracking-with-opencv/
Is using these code?
try{
//print something here
Thread.sleep(3000); //sleep for 3 seconds
//print something else here
}
catch(InterruptedException e){
System.out.println("got interrupted!");
}
How should I combine? Actually the part of the code is detect the eye, now I want to do is detect the eye with 5 seconds after that will jump to another function code.
What code I can put to combine with them? Need help to answer if you have any idea.
Thanks
Run first method
2.For executing something in the UI Thread after 5 seconds:
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
// Stop 1st one
// run 2nd
}
}, 5000);
public void save()
{ Presentation pres = new Presentation(filename);
ISlide slide = pres.getSlides().get_Item(0);
IShape shape= null;
for (int i = 0 ; i < slide.getShapes().size() ; i++)
{ shape = slide.getShapes().get_Item(i);
if (shape.getPlaceholder() != null)
{
((IAutoShape)shape).getTextFrame().setText(txtArea.getText());
}
}
pres.save(filename,SaveFormat.Ppt);
}
This code is for changing the text but it's not working. I have used two APIs at a time, display code is below:
public void Display(int currentPage, String source)
{
try {
// Create a slideshow object; this creates an underlying POIFSFileSystem object for us
SlideShow ppt = new SlideShow(new HSLFSlideShow(source));
current=currentPage;
// Get all of the slides from the PPT file
Slide[] slides = ppt.getSlides();
Dimension pgsize = ppt.getPageSize();
all = slides.length;
String temp="";
lblPage.setText(currentPage+" / "+all);
BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = img.createGraphics();
graphics.setPaint(Color.white);
graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
//render
slides[currentPage-1].draw(graphics);
//save the output
/*FileOutputStream out = new FileOutputStream("slide-" + (i + 1) + ".png");
javax.imageio.ImageIO.write(img, "png", out);
out.close();
//ImageIcon icon = new ImageIcon("slide-" + (i + 1) + ".png");*/
ImageIcon icon = new ImageIcon(img);
lblPresentasi.setIcon(icon);
// Obtain metrics about the slide: its number and name
int number = slides[currentPage-1].getSlideNumber();
String title = slides[currentPage-1].getTitle();
// Obtain the embedded text in the slide
TextRun[] textRuns = slides[currentPage-1].getTextRuns();
System.out.println("Slide " + number + ": " + title);
System.out.println("\tText Runs");
txtArea.setText("Slide : " + number + " Title : " + title + "\n");
for (int j = 0; j < textRuns.length; j++) {
// Display each of the text runs present on the slide
System.out.println("\t\t" + j + ": " + textRuns[j].getText());
temp=txtArea.getText();
txtArea.setText(temp+"\t\t" + textRuns[j].getText() + "\n");
}
// Obtain the notes for this slide
System.out.println("\tNotes: ");
Notes notes = slides[currentPage-1].getNotesSheet();
if (notes != null) {
// Notes are comprised of an array of text runs
TextRun[] notesTextRuns = notes.getTextRuns();
for (int j = 0; j < notesTextRuns.length; j++) {
System.out.println("\t\t" + notesTextRuns[j].getText());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Can anyone please help, I am trying to make a simple powerpoint editor in Java.
I want to change text in textarea press save button so text has to change and call display function.
I have observed your sample code and like to share that as far as code related to Aspose.Slides is concerned, there is no issue and it is perfectly right. You can verify this by opening the saved presentation with changed text in PowerPoint. If you encounter any issue in this, we will be glad to help you further. You may also contact us in Aspose.Slides support forums as well.
I work with Aspose as Developer evangelist.
I am trying to combign tiff image and shapefile and want show it. For this, I am using GeoTiff and I am stuck that my tiff file is now being displayed. Shapefile is showing properly but tiff image, which is having only 1 band and grey scale index, is not being shown because of some reason. I am getting one warning message as below.
2016-08-04T12:43:06.456+0530 WARNING Possible use of "Transverse_Mercator" projection outside its valid area.
Latitude 180°00.0'S is out of range (±90°).
How can I remove this message?
My code is as below
private void displayLayers() throws Exception {
AbstractGridFormat format = GridFormatFinder.findFormat(this.getBlueMarble());
this.setGridCoverageReader(format.getReader(this.getBlueMarble()));
Style rgbStyle = this.createRGBStyle();
// connect to the shapefile
FileDataStore dataStore = FileDataStoreFinder.getDataStore(this.getBorderShape());
SimpleFeatureSource shapefileSource = dataStore.getFeatureSource();
Style shpStyle = SLD.createPolygonStyle(Color.BLUE, null, 0.0f);
MapContent map = new MapContent();
map.getViewport().setCoordinateReferenceSystem(
DefaultGeographicCRS.WGS84);
map.setTitle("Illegal Mining");
Layer rasterLayer = new GridReaderLayer(this.getGridCoverageReader(), rgbStyle);
map.addLayer(rasterLayer);
Layer shpLayer = new FeatureLayer(shapefileSource, shpStyle);
map.addLayer(shpLayer);
System.out.println("Trying to show on map...");
JMapPane mapPane = new JMapPane();
mapPane.setMapContent(map);
mapPane.setDisplayArea(shapefileSource.getBounds());
//mapPane.setDisplayArea(this.getGridCoverageReader().getOriginalEnvelope());
this.add(mapPane, BorderLayout.CENTER);
}
private Style createRGBStyle() {
GridCoverage2DReader reader = this.getGridCoverageReader();
StyleFactory sf = this.getStyleFactory();
GridCoverage2D cov = null;
try {
cov = reader.read(null);
} catch (IOException giveUp) {
throw new RuntimeException(giveUp);
}
// We need at least three bands to create an RGB style
int numBands = cov.getNumSampleDimensions();
System.out.println("numBands:"+numBands);
if (numBands < 3) {
System.out.println("Bands are less than 3");
//return null;
}
// Get the names of the bands
String[] sampleDimensionNames = new String[numBands];
for (int i = 0; i < numBands; i++) {
GridSampleDimension dim = cov.getSampleDimension(i);
sampleDimensionNames[i] = dim.getDescription().toString();
}
final int RED = 0, GREEN = 1, BLUE = 2;
int[] channelNum = { -1, -1, -1 };
Boolean greyflag=false;
// We examine the band names looking for "red...", "green...",
// "blue...".
// Note that the channel numbers we record are indexed from 1, not 0.
for (int i = 0; i < numBands; i++) {
String name = sampleDimensionNames[i].toLowerCase();
System.out.println("name :"+name);
if (name != null) {
if (name.matches("red.*")) {
channelNum[RED] = i + 1;
} else if (name.matches("green.*")) {
channelNum[GREEN] = i + 1;
} else if (name.matches("blue.*")) {
channelNum[BLUE] = i + 1;
}else if(name.matches("gray.*")){
System.out.println("What to do here");
channelNum[RED] = 1;
channelNum[GREEN] = 2;
channelNum[BLUE] = 3;
greyflag=true;
}
}
}
// If we didn't find named bands "red...", "green...", "blue..."
// we fall back to using the first three bands in order
if(greyflag==false){
if (channelNum[RED] < 0 || channelNum[GREEN] < 0
|| channelNum[BLUE] < 0) {
channelNum[RED] = 1;
channelNum[GREEN] = 2;
channelNum[BLUE] = 3;
}
}
// Now we create a RasterSymbolizer using the selected channels
SelectedChannelType[] sct = new SelectedChannelType[cov
.getNumSampleDimensions()];
ContrastEnhancement ce = sf.contrastEnhancement(this.ff.literal(1.0),
ContrastMethod.NORMALIZE);
for (int i = 0; i < numBands; i++) {
sct[i] = sf.createSelectedChannelType(
String.valueOf(channelNum[i]), ce);
System.out.println(String.valueOf(channelNum[i]));
}
RasterSymbolizer sym = sf.getDefaultRasterSymbolizer();
ChannelSelection sel =sf.channelSelection(sct[RED]);
if(numBands>1){
sel = sf.channelSelection(sct[RED], sct[GREEN],
sct[BLUE]);
}
sym.setChannelSelection(sel);
return SLD.wrapSymbolizers(sym);
}
I just pass two files as below code
public MapImagePanel() {
this.setLayout(new BorderLayout(0, 0));
this.setBackground(Color.BLUE);
this.setPreferredSize(new Dimension(720, 360));
this.setBlueMarble(new File("E:/tifffilename.TIFF"));
this.setBorderShape(new File("E:/shapefilename.shp"));
try {
this.displayLayers();
} catch (Exception e) {
e.printStackTrace();
}
}
This is how i use this class in main class
//see output in main method
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MapImagePanel panel = new MapImagePanel();
panel.setPreferredSize(new Dimension(1024,768));
panel.setVisible(true);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
frame.show();
TLDR; add the following line to your program start up:
System.setProperty("org.geotools.referencing.forceXY", "true");
From GeoTools FAQ as computer programmers they knew that coordinates would be expressed as longitude,latitude pairs so they could use existing graphics code easily by treating them as a simple (x,y) pair. but for sequence like (x,y) or (y,x) they confused that is why this error is coming.