Loading an image saved at runtime

Started by
24 comments, last by Aldacron 8 years, 4 months ago


gBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); returns the compressed file, i hava also used countless times

(Emphasis added)

No, it does not. Bitmap.compress() returns a boolean, which is either true or false. A function returning something is very different to a function doing something, which is what you seem to be talking about.

This tells me you need to look into checking what functions return. Once this concept is clear, check the documentation for the functions you use, and see if the functions return what you expect them to.

I'd still suggest looking more closely at the 2 functions I mentioned to start with. Do they return what you would expect? Check and verify this properly, not by deducing or guessing or feeling.

Hello to all my stalkers.

Advertisement


(Emphasis added)
No, it does not. Bitmap.compress() returns a boolean, which is either true or false. A function returning something is very different to a function doing something, which is what you seem to be talking about.

This tells me you need to look into checking what functions return. Once this concept is clear, check the documentation for the functions you use, and see if the functions return what you expect them to.


I'd still suggest looking more closely at the 2 functions I mentioned to start with. Do they return what you would expect? Check and verify this properly, not by deducing or guessing or feeling.

This is the rest of the documentation from eclipse. It may return boolean, but it also does the compression and i have always used it to compress from bitmap to jpeg or png

boolean android.graphics.Bitmap.compress(CompressFormat format, int quality, OutputStream stream)

Write a compressed version of the bitmap to the specified outputstream. If this returns true, the bitmap can be reconstructed by passing a corresponding inputstream to BitmapFactory.decodeStream(). Note: not all Formats support all bitmap configs directly, so it is possible that the returned bitmap from BitmapFactory could be in a different bitdepth, and/or may have lost per-pixel alpha (e.g. JPEG only supports opaque pixels).

Parameters: format The format of the compressed image quality Hint to the compressor, 0-100. 0 meaning compress for small size, 100 meaning compress for max quality. Some formats, like PNG which is lossless, will ignore the quality setting stream The outputstream to write the compressed data. Returns: true if successfully compressed to the specified stream.

can't help being grumpy...

Just need to let some steam out, so my head doesn't explode...

Yes, but it returns true if everything was succesful. If it returns false, then you know that one of the parameters you pass into the function is incorrect in some way, and you can start looking deeper and figuring out what's wrong.

Your code is not doing what you want, so something is wrong. Saying "I have always used it" does not mean it works this time.

This is why you want to check the return values of functions, to see when/where/why they fail.

EDIT: spacebardidntwanttoregister+ you're vs your.

Hello to all my stalkers.


Yes, but it returns true if everything was succesful. If it returns false, then you know that one of the parameters you pass into the function is incorrect in someway, and you can start looking deeper and figuring out what's wrong.
You're code is not doing what you want, so something is wrong. Saying "I have always used it" does not mean it works this time.

This is why you want to check the return values of functions, to see when/where/why they fail.

Just did a quick run checking that now and you are right, it returns false

But the line would be red-lined if the parameters are wrong types, but not if its null.

So the JPEG i extracted to directories and supposedly loaded to the program is null. It may still boil down to the fact that maybe it is not possible to save and load to program in the same runtime (same executable runtime), or is it? Has anyone tried that before and confirm whether that's possible or not

(sorry for my mixed-up terminologies , its not on purpose)

can't help being grumpy...

Just need to let some steam out, so my head doesn't explode...

Then you go back further, and inspect the variables you pass in. Are they correct?

If I had to guess, I'd guess gBitmap is null, because of the decodeFile function returning null when you call it before save_bm_image.

If that's the case, I'd guess that's due to your path of file name being incorrect (even though you think it's correct).

Step through the code, look at what the variables are and what they should be. At some point, they will be something they shouldn't be -- that's most likely where your bug is.

Hello to all my stalkers.


It may still boil down to the fact that maybe it is not possible to save and load to program in the same runtime (same executable runtime), or is it?


Please just throw this idea away and never let it return to your head. It has always been, and will always be, possible for Java programs to save and load the same image as many times as you would like during the same execution of a program. This is not your problem.

No matter which programming language you use to write a program, always, always, always check return values. Never assume that something working today will work tomorrow. When a return value isn't want it should be, log it and react accordingly. Logging it is the most important thing here. It will help you narrow down the source of most problems more quickly.

This topic is closed to new replies.

Advertisement