picture path into, and finally notify the library update.So write a method, the complete code is as follows:PublicStaticvoidSaveimagetogallery(ContextContext,BitmapBmp){//Save the picture firstFileAppdir=NewFile(Environment.getExternalStorageDirectory(),"Boohee");If(!Appdir.Exists()){Appdir.Mkdir();}StringFileName=System.Currenttimemillis()+". jpg";FileFile=NewFile(Appdir,FileName);Try{FileOutputStreamFos=NewFileOutputStream(File);Bmp.Compress(Compre
""true"); //Aspectx aspecty is the ratio of width to height, where the square is set (aspect ratio is 1:1)Intent.putextra ("Aspectx", 1); Intent.putextra ("Aspecty", 1); //Outputx outputy is a cropped image with a wide height of Intent.putextra ("OUTPUTX"); Intent.putextra ("outputy"); Intent.putextra ("Return-data"true); cut_ok);}4. Display and save pictures/** * Save the picture data aft
made by the user are saved in memory
2 When the system reclaims the memory and destroys the activity, it cannot save its state, so it is necessary to call the Onsaveinstancestate () method to save the state.
3 Many situations do not need to maintain state information, such as press the return key to close the program directly, so it is not guaranteed to call onsaveinstancestate. If this method is invoked
"Share" Android Studio dedicated file Conversion tool: Save ANSI files in bulk as UTF-8 files without BOMWhen compiling Java files under Andoird Studio, there are often errors like the following:Error: (29, 43) downloading message: Ke policy home UTF-8 fermium Âμà switches Å è¡#̈亞 槧 hao 勫 瓧 quilting?Here, share a tool: ANSI files are saved in bulk as UTF-8 files without a BOM:Save the following code in No
() to save the fragment state, using the following code:private void Replacecontainer (MenuItems menuItem) {fragmenttransaction transaction = Fragmentmanager.begintransaction (); Transaction.setcustomanimations (r.anim.right_in, R.anim.left_fadeout,r.anim.right_fadein, R.anim.left_fadeout ); Fragment Fragment = Retrievefromcache (MenuItem);//Fragment is not instantiated, new is added to the fragmenttransaction, and the state of Fragment is saved if (
Onsaveinstancestate (Bundle outstate) {In the activitySave the necessary data before the system automatically destroys the activity @overridepublic void Onsaveinstancestate (Bundle outstate) {Here is an important point, above the above mentioned Onsaveinstancestate () method only when the activity or fragment determined to be automatically purged by the system, will be called, if not long-term background applications, the page is not killed by the system, The corresponding activity or fragment
]; Bytearrayoutputstream baos=new Bytearrayoutputstream ()///while ((Len=fis.read (buffer))!=-1 to output data in memory//If the amount of data is large, The data read for the 2nd time is likely to overwrite the 1th reading of the data {Baos.write (Buffer,0,len);} Byte[] Data=baos.tobytearray ();//Get the in-memory data stored in binary baos.close (); Fis.close (); return new String (data);// Converted to the corresponding string according to the binary data}}Fileservicetest.java (Identification
Android uses setTag twice at the same time to save multiple values. androidsettag
Sample Code:
View. setTag (R. string. action_settings, hodler. content );
Receive two values. One is the key value and must be a unique value. It must be written in values/string. xml, for example
.......
The final call is as follows:
View. setTag (R. id. ffffff, the value you want to
Onsaveinstancestate is saved after a pause and before saving is calledOnrestoreinstancestate restore after restart and before the display is called Packagecom.example.chenshuai.excise;Importandroid.app.Activity;Importandroid.content.Intent;ImportAndroid.os.Bundle;ImportAndroid.util.Log;ImportAndroid.view.View;/*** Created by Chenshuai on 2016/3/20.*/ Public classExcise1extendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); S
: File object
Get gets network data, gets input stream, loops read save
The read input stream is written to the file output stream
Returns the URI object
Unable to update UI in child thread, update UI with handler technology
In the Handlemessage method inside the handler inner class, get to the URI object
Invokes the Setimageuri () method of the ImageView object, showing the picture, parameter: Uri object
Clear Cache
Clears all cached files wh
Android media files (images, videos, audios, and other files) must be scanned to the media library for viewing through related programs. For exampleWrite a program to download an image from the Internet and save it to the sdcard. Exit the program and open the system image program.This is because the image is not registered in the system media library. When the system starts (or when sdcard is loaded again),
, such as Directory_music and Directory_ringtones, which represent the music directory and the ringtone directory, respectively. If the specified directory does not exist, the directory is created. By specifying a directory type, you can have the Android multimedia scanner categorize your files. If your application is uninstalled by the user, the directory and content stored in this way will be removedIf you are using LEVEL7 or earlier APIs, use getEx
Read and write functions such as the following: Orz, did you find anything? Yes, these two functions have nothing to do with Android.So they can be used in other standard Java programs as well.In Android, it is better to read and write from a pure string, parse it yourself, or use XML to save the configuration.Properties appear simpler and more intuitive, due to the need for a lot of code, and XML operation
Android-save several formats as jpeg files
// 1. the YuvImage class in NV21 format is used for storage efficiency. String fileName = "IMG _" + String. valueOf (index) + ". jpg "; File sdRoot = Environment. getExternalStorageDirectory (); String dir = "/picture/"; File mkDir = new File (sdRoot, dir); if (! MkDir. exists () {mkDir. mkdirs ();} File pictureFile = new File (sdRoot, dir + fileName); if (! Pictur
[Android] how to save a view as an image and solve the problem of changing the background of the saved image to black,
Code:
Public class MainActivity extends Activity {ImageView imgView; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); imgView = (ImageView) findViewById (R. id. imageView); imgView. setDrawingCac
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.