Unable to find saved image - android

I'm very new to Android. I'm working with Xamarin and I have to take a picture with camera and save the picture.
I achieved to take the picture, I have a Bitmap object. Then I save it without error but when I try to find it, there is no file.
There is my code :
Bitmap imgBmp = /* image initialized */
//Save image on folder
var folderPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var filePath = System.IO.Path.Combine(folderPath, "image1.png");
var stream = new System.IO.FileStream(filePath, FileMode.Create);
bool isOK = imgBmp.Compress(Bitmap.CompressFormat.Jpeg, 95, stream);
stream.Flush();
stream.Close();
I have no error when execute, isOK is true but when I search for the image.png I'm unable to find the file.
With debugger I saw that the path is : /data/user/0/com.myCompagny.MyAppli/files/image1.png but I can not see that folder.
Can someone help me to find my image1.png ?
Or to change the default folder to something like Pictures\MyApplication\image.png but I don't know how to find default folder for images.

Your file is there, but you have no permissions to see it. App directories are only readable to the owning app's uid. If you try to find your file through the shell, your uid is different.
You should try to use another folder path if you want to save file in a world readable location.
I'm just guessing but maybe System.Environment.SpecialFolder.CommonPictures would do.

Related

Write a ByteArrayOutputStream as a file to data/data/packagename/files

I have compactFile: ByteArrayOutputStream() and I want to create a file in the directory
data/data/package.name/files
So what I do is inside a Workmanager
Application.instance.openFileOutput(localUriName, Context.MODE_PRIVATE).use {
it.write(compactFile.toByteArray())
}
The compactFile can be a an Image or a Video or a Document or whatever.
However, sometimes the file never gets saved in the path. And I want to understand why is this happening. Is there a size limitation issue? Is it because I don't do it right..? Any ideas?

Can't display image formatted png on Android

Today I encounter a strange question. I have a png image "image.png", which is generatied by Java code, and anthor image "a.png". I import them to /sdcard/image/ directory. When I invoke code
Bitmap bit = BitmapFactory.decodeFile("/sdcard/image/image.png");
and
bit = BitmapFactory.decodeFile("/sdcard/image/a.png");
on Android, the first bit is null but the latter is not. I am sure the path "/sdcard/image" is right.
Could you help me???
You can get the path of sdcard from this code:
File extStore = Environment.getExternalStorageDirectory();
Then specify the foldername and file name
"/image/"+"image.jpg"
bit = BitmapFactory.decodeFile(extStore +"/image/a.jpg");

can not load my image into a bitmap class in android

hi i have a problem with a bitmap and a picture located here:
file:///mnt/sdcard/Android/data/com.dev.app/files/Pictures/20120924-092226.jpg
so i have a string with this url (the the file exists!)
now i need to get a bitmap, so i do:
String str = "file:///mnt/sdcard/Android/data/com.dev.app/files/Pictures/20120924-092226.jpg";
Bitmap b = BitmapFactory.decodeFile(str);
but b is always null. and i dont know why.
EDIT: i create the file before with a code like this:
String filename = DateFormat.format("yyyyMMdd-hhmmss",Calendar.getInstance().getTime()) + ".jpg";
Uri imageUri = helper.createImageDestinationUri(null, filename);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, requestCode);
There are two possibilities
The file is of incorrect format, i.e although the extension is .jpg its not a jpeg file.
The file cannot be loaded.
You may have a closer look at the adb logs to see what is going on ... if it does not helps , try the following.
Add the file in your drawable folder, and use it in some Test screen. If the file gets displayed then the file format is correct , so android is not able to load the file. Check your permissions, and actually try and read the file first using FileInputStream or somthing else.
If the file is still not displayed then you can be sure that the format is wrong. In that case just try using a different image file.
Hope it helps...

Adobe Flex AIR download videos in Android device

I want to download a set of video files to a default folder path in an Android device and then have access to the path and files. The FileReference class does not support this features. Is there another way? Thank you.
I dont use file reference at all. I use a Loader to download the file. I then create a new File object with the path where I want to save the file, and use a FileSteam to write the data from the loader to the file.
var req:URLRequest = new URLRequest(url);
loader = new URLLoader();
loader.addEventListener(Event.COMPLETE, handler);
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.load(req);
function handler(e:Event):void{
var file:File = new File(path);
var stream:FileSteam();
steam.open(file, FileMode.WRITE);
steam.writeBytes(loader.data);
steam.close();
}
something like this should accomplish what you are looking for. I wrote this code from memory so it may not be exactly correct but should be good enough to get you going. Make sure you put this in a try/catch since file and filesteam both throw exceptions

Android moving a photo from one folder to another

I'm using the below code to transfer an image from one folder on external memory, to another..as specified by the user. The problem is, the photo gets copied to the destination folder fine..but I can't open or view it. I use a file manager named Astro to see if it was successfully moved, and it is..but I'm unable to open it both in Astro and in the resident Gallery app. I'm thinking something is wrong with my code and maybe I need read and/or decode to photo before I can move it, from what I understand about the File class it is just an abstraction. Any guidance on this would be greatly appreciated, here is the code I'm currently using.
File img = new File(imgViewPath);
File output = new
File(Environment.getExternalStorageDirectory().toString() + "/MyAppPics/" + moved,
img.getName());
OutputStream out = null;
try {
out = new BufferedOutputStream(new FileOutputStream(output));
}
finally {
if (out != null) {
out.close();
}
}
}catch(Exception e){
e.printStackTrace();
}
You are not writing anything to the output stream. Read the bytes from the input stream and write it to the output stream, only then the files will get copied.

Categories

Resources