Public Group

This topic is 926 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Is there a way to load an image, saved at the same runtime, in JAVA?

It might look like it doesn't make sense but it does in my current project. My attempt hasn't worked. I only ended up re-saving a jpg place holder, while the same code saves an actual jpg if the image was save before current runtime.

thanx

##### Share on other sites

It is completely possible. Are you using a graphics library or standard java methods? Ive only ever used java in an elementary fashion so I am not very learned in it, but their is no reason at all as to why you could not do what you want to do.

All you need is the path that you saved the image to and than reload it using whatever standard methods exist in java.

Here is a quick and dirty from google.

Edited by ExErvus

##### Share on other sites

All you need is the path that you saved the image to and than reload it using whatever standard methods exist in java.

Here is a quick and dirty from google.

Like i said i tried that but it only had a place holder.  I'v been loading and saving images successfully countless times, using stnadard methods. But this time it being the same runtime seem to make the difference and it hasn't worked

##### Share on other sites

I'v been loading and saving images countless times, using stnadard methods, but this it being the same runtime seem to make the difference and it hasn't worked

Perhaps if you pasted a few snippets of your pertinent code it may help us find your problem.

Edited by ExErvus

##### Share on other sites

This works perfectly well if its not the same run time. The main issue is loading the image saving at the same runtime. At the same runtime it merely saves a placeholder for jpeg

saveFiles();                                                                                      is where the first save of the jpeg
			 public void onClick(View view) {
readFromFile( pathPlusfile, ImageDir3 + "/QCD/", QCD_txt_file  );
appendToFile( pathPlusfile, baseString+numFromFile, numFromFile=numFromFile+1  );

saveFiles();          // for clarity i chandged the function name to saveFiles()

BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
save_bm_image( WBL_reloaded, ImageDir3 + "/QCD/", "newrTest.jpg"  );
}
});

void save_bm_image( Bitmap gBitmap, String path, String fname  ){

File file = new File (path, fname);
if (file.exists ()) file.delete ();
try {
FileOutputStream out = new FileOutputStream(file);
gBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}



##### Share on other sites
I still have no real clue what you are talking about or what your exact problem is. I'm not even sure what you mean by "loading the image saved at the same runtime". Are you referring to loading an image you saved earlier during the same run of the executable?
Usually, 'runtime' is used to distinguish problems happening at different stages of the build process (for example: compile time, link time and run time). Runtime is also often used in the context of a runtime library which refers for example to C++'s runtime library or Java's class library (often but not always in the form of some dynamic library).
In your own interest you might want to abandon an expression that is loaded with different meanings and describe your problem in a another way.

I don't really understand your code either. Java's class library changed either significantly since I last looked at it or important portions of that code are your own but not posted in any way. A few hints out of the top of my head:
- are you absolutely sure your image writes are completed successfully, that is without some error?
- are you certain the functions you use do not return until the read/write operation is completed? It is possible the functions return immediately and do their work in another thread.
- are you certain you do not have unexpected names for your files (for example writing image3.jpg and then trying to load image4.jpg)?
- since I don't really understand what the exact problem is: you are aware that JPEG is a lossy format and images repeatedly read and rewritten will accumulate increasing degradation due to compression artifacts?

##### Share on other sites

Ok, what i mean by runtime is "while the program is still running".

Unfortunately the whole of my code is too large to place here and might even confuse more so i will explain more simplistically

Normally   : program is running.  I load image which is already extracted and saved before current progam,- from memory into progam'

i do whatever i want to do with the image in the code

I save jpeg  image back to directory on disk      (this worked)        saves actual jpeg image

Current  problem   program is running.   I extract zipfile. Normally this saves to specified directories. (i have tested in various ways and its fine)

Next while program is still running i want to load this files saved in the step immediate above ^ from memory

I save jpeg  image back to directory on disk   (this doesn't work)  only saves jpeg place-holder

Sorry i forgot to mention its Android JAVA

Many functions are mine, some are android's and some Java

##### Share on other sites

I save jpeg image back to directory on disk (this doesn't work)

What does not work? You keep saying something goes wrong without ever describing it in sufficient detail. Does it crash during the write? Is an exception thrown (if so, what exception including the stack trace)? Is there no file (is the path correct and can you create, for example, a simple text file instead)? Does the file have the wrong content?

Sorry i forgot to mention its Android JAVA

Whether it's Android or not, the language is still called just Java. It's a name, not an acronym for anything. Edited by BitMaster

##### Share on other sites

No crash, no exception, no errors

But when i check the directory for the jpg file ,  the place-holder is there but when i open - there is no jpeg file. This is what doesn't work - No jpeg file, just placeholder. I did mention this though

(is the path correct and can you create, for example, a simple text file instead)?

The path is correct, otherwise it won't work in the case 1 abbove, nor would it know where to save the place-holder. The place holder is in right directory but without the actual jpg file

I didn't change too much (nor the file path) between first case and second case

I'm just suspecting Java can't handle loading and  saving (of the same object at  the same run executable  -as you termed it,), or if it can i will like to know how, which is the purpose of this thread anyway.

Because my code would work much better that way, rather than having to close the program and start run again to make it work

Edited by alwaysGrey

##### Share on other sites

no errors

Just to verify, does your code contain error checking which has been removed in the code snippet you posted earlier in this thread? I ask because the code you posted does not check for errors in all the places where the code could return errors.

Also, I'm a bit unsure what a "jpeg place-holder" is. Is this the save file you loaded in the first place, an empty file, or something else?

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
18

• 11
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631420
• Total Posts
2999990
×

## Important Information

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!