Saving images into a folder in android? - android-camera

Hello am using camera in my application.So i want to save Captured images into folder in gallery,floder name must be application name?please suggest me with some Example?
Thanks in advance

You can create any folder or file you want. Read this Android article Taking Photos Simply:
Add the Photo to a Gallery When you create a photo through an intent,
you should know where your image is located, because you said where to
save it in the first place. For everyone else, perhaps the easiest way
to make your photo accessible is to make it accessible from the
system's Media Provider.
The following example method demonstrates how to invoke the system's
media scanner to add your photo to the Media Provider's database,
making it available in the Android Gallery application and to other
apps.
private void galleryAddPic() {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(mCurrentPhotoPath);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
this.sendBroadcast(mediaScanIntent);
}

Use below code and modify the path where you want to save your image.
mImageView.setDrawingCacheEnabled(true); Bitmap bitmap =
mImageView.getDrawingCache();
String root = Environment.getExternalStorageDirectory().toString();
File newDir = new File(root + "/app_name/saved_images"); newDir.mkdirs();
Random gen = new Random(); int n = 10000; n = gen.nextInt(n); String
fotoname = "photo-" + n + ".jpg"; File file = new File(newDir,
fotoname); String s = file.getAbsolutePath();
System.err.print("******************" + s); if (file.exists())
file.delete(); try { FileOutputStream out = new
FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG,
90, out); out.flush(); out.close();
Toast.makeText(getApplicationContext(), "Saved to your folder ",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
}

Related

Load all existent files (sprites) from Application.persistentDataPath? Unity

In my game, you can take screenshots of the world, which are saved in Application.persistentDataPath. I want to make a gallery where you can then see all these screenshots. Because you need to write to the file, I can't use Resources folder or Application.streamingAssetsPath. I could read the files one sprite at a time, using the name, but that's not really practical. So how could I load all files and add them to an array or list? I basically need the equivalent of Resources.LoadAll(). Does anyone know how to achieve this?
You can use Directory.GetFiles(string,string) to return all filepaths in the persistentData folder e.g. by file extension ("*.jpg")
Then you can use e.g. UnityWebRequestTexture.GetTexture also on local file paths and load assets from the persistent data path like
public Dictionary<string, Texture2D> textures = new Dictionary<string, Texture2D>();
private void Start()
{
var fileNames = Directory.GetFiles(Application.persistentDataPath, "*.jpg");
foreach(var fileName in fileNames)
{
StartCoroutine (LoadFile(fileName));
}
}
private IEnumerator LoadFile(string filePath)
{
using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(filePath))
{
yield return uwr.SendWebRequest();
if (uwr.isNetworkError || uwr.isHttpError)
{
Debug.Log(uwr.error);
}
else
{
// Get downloaded asset bundle
var texture = DownloadHandlerTexture.GetContent(uwr);
// Something with the texture e.g.
// store it to later access it by fileName
var fileName = Path.GetFileName(filePath);
textures[fileName] = texture;
}
}
}

How-to get the code for downloading metadata along with images in IBM content manager

I am trying to find the code in java API which works with cm IBM.. the sample code is there but it is just for logging in.. can anyone help to get the code to download the images along with metadata
as you said you have basic connection code, use the below function to download the document..
public String retrieveDocument(CMBConnection connection, CMBItem item)
throws CMBException, IOException, Exception
{
// Get an instance of data management bean
CMBDataManagement dataManagement = connection.getDataManagement();
// Set the current data item
dataManagement.setDataObject(item);
// Retrieve the original file name
CMBObject object = dataManagement.getContent(0);
String inputFileName = object.getOriginalFileName();
// Parse the file name from the full path
int pos=inputFileName.lastIndexOf("\\");
inputFileName = inputFileName.substring(pos+1);
// Write the document content to a new file
String fileName = System.getProperty("user.dir")
+ File.separator + inputFileName;
System.out.println("Output file name " + fileName);
FileOutputStream fileoutstream = new FileOutputStream(fileName);
fileoutstream.write(dataManagement.getContent(0).getData());
fileoutstream.close();
// Return file name
return fileName;
}

Solution to upload image file via WCF service?

Being surfing for last 3-4 days downloading, running and fixing issues with available demo projects online, none of them work so far.
I need to upload an image using WCF webservice. Where from client side end I like to upload it by means of form (multipart/form-data), including some file description.
Any solution working with proper answer? My mind is really stacked overflow trying different solution. One which I initially have I am able to upload a text file where file gets created with some extra content in it. I need to upload image file.
------------cH2ae0GI3KM7GI3Ij5ae0ei4Ij5Ij5
Content-Disposition: form-data; name=\"Filename\"
testing file gets upload...
When I upload image file, the image file is empty.
Initial Code (one implantation), method by means of which I get the .txt file as above, in case of image its blank (or say corrupt don't know)
private string uplaodFile(Stream stream)
{
StreamReader sr = new StreamReader(stream);
int length = sr.ReadToEnd().Length;
byte[] buffer = new byte[length];
stream.Read(buffer, 0, length);
FileStream f = new FileStream(Path.Combine(HostingEnvironment.MapPath("~/Upload"), "test.png"), FileMode.OpenOrCreate);
f.Write(buffer, 0, buffer.Length);
f.Close();
stream.Close();
return "Recieved the image on server";
}
another;
public Stream FileUpload(string fileName, Stream stream)
{
string FilePath = Path.Combine(HostingEnvironment.MapPath("~/Upload"), fileName);
int length = 0;
using (FileStream writer = new FileStream(FilePath, FileMode.Create))
{
int readCount;
var buffer = new byte[8192];
while ((readCount = stream.Read(buffer, 0, buffer.Length)) != 0)
{
writer.Write(buffer, 0, readCount);
length += readCount;
}
}
return returnJson(new { resp_code = 302, resp_message = "occurred." });
}

Openxml: Added ImagePart is not showing in Powerpoint / Missing RelationshipID

I'm trying to dynamically create a PowerPoint presentation. One slide has a bunch of placeholder images that need to be changed based on certain values.
My approach is to create a new ImagePart and link it to the according Blip. The image is downloaded and stored to the presentation just fine. The problem is, that there is no relationship created in slide.xml.rels file for the image, which leads to an warning about missing images and empty boxes on the slide.
Any ideas what I am doing wrong?
Thanks in advance for your help! Best wishes
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite siteCollection = new SPSite(SPContext.Current.Site.RootWeb.Url))
{
using (SPWeb oWeb = siteCollection.OpenWeb())
{
SPList pictureLibrary = oWeb.Lists[pictureLibraryName];
SPFile imgFile = pictureLibrary.RootFolder.Files[imgPath];
byte[] byteArray = imgFile.OpenBinary();
int pos = Convert.ToInt32(name.Replace("QQ", "").Replace("Image", ""));
foreach (DocumentFormat.OpenXml.Presentation.Picture pic in pictureList)
{
var oldimg = pic.BlipFill.Blip.Embed.ToString(); ImagePart ip = (ImagePart)slidePart.AddImagePart(ImagePartType.Png, oldimg+pos);
using (var writer = new BinaryWriter(ip.GetStream()))
{
writer.Write(byteArray);
}
string newId = slidePart.GetIdOfPart(ip);
setDebugMessage("new img id: " + newId);
pic.BlipFill.Blip.Embed = newId;
}
slidePart.Slide.Save();
}
}
});
So, for everyone who's experiencing a similar problem, I finally found the solution. Quite a stupid mistake. Instad of PresentationDocument document = PresentationDocument.Open(mstream, true); you have to use
using (PresentationDocument document = PresentationDocument.Open(mstream, true))
{
do your editing here
}
This answer brought me on the right way.

Downloading some files

I want to download a file and save it into my app folder. I have to download different files with different formats, but only one each time.
I've read that I have to use HttpUtils, but sample codes are to difficult for me (I'm too noob).
Can anyone upload any sample code?? Thanks!!
This should point you in the right direction:
URL u = new URL(urlString);
HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
File file = new File(outputDirectoryFile, outputFileName);
OutputStream out = new FileOutputStream(file);
InputStream in = c.getInputStream();
byte[] buffer = new byte[4096];
while ( (int len1 = in.read(buffer)) > 0 ) {
out.write(buffer,0, len1);
}
in.close();
out.close();
c.disconnect();
Remember, you should never perform operations like this on the default UI tread. It could prompt the user to force close your app. Read more here:
http://developer.android.com/resources/articles/painless-threading.html
This is how I finally do:
imgurl = "http://dl.dropbox.com/u/25045/file.jpg"
HttpUtils.CallbackActivity = "myactivity" 'Current activity name.
HttpUtils.CallbackJobDoneSub = "JobDone"
HttpUtils.Download("Job1", imgurl)
Dim out As OutputStream
out = File.OpenOutput(File.DirInternal, "file.jpg", True)
File.Copy2(HttpUtils.GetInputStream(imgurl), out)
out.Close