有人可以解释为什么从hsv转换回rgb时,从rgb转换为hsv不会得到相同的结果?
int color = Color.rgb(206, 43, 55);
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
System.out.println(red + ", " + green + ", " + blue);
//prints: 206, 43, 55 (as expected)
float[] hsv = new float[3];
Color.RGBToHSV(red, green, blue, hsv);
float hue = hsv[0];
float sat = hsv[1];
float val = hsv[2];
int outputColor = Color.HSVToColor(hsv);
red = Color.red(outputColor);
green = Color.green(outputColor);
blue = Color.blue(outputColor);
System.out.println(red + ", " + green + ", " + …Run Code Online (Sandbox Code Playgroud) 我已经阅读了关于这个论点的所有答案,但我总是收到收到我的照片的应用程序的错误.
不仅如此方式工作对我来说,所有的应用程序,是这样的(它的工作原理,因为SD卡的文件都是公开的所有应用程序):
final File tmpFile = new File(context.getExternalCacheDir(), "exported.jpg");
Uri tmpFileUri = Uri.fromFile(tmpFile);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setDataAndType(tmpFileUri, "image/jpeg");
shareIntent.putExtra(Intent.EXTRA_STREAM, tmpFileUri);
context.startActivity(Intent.createChooser(shareIntent, context.getString(R.string.share_image)));
Run Code Online (Sandbox Code Playgroud)
现在,我坚持如何共享位于私人文件夹中的文件.我使用了google文档提供的代码:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.test.myapp.fileprovider"
android:exported="false"
android:grantUriPermissions="true" >
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>
...
...
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="internal_files" path="/"/>
<cache-path name="internal_cache" path="/" />
</paths>
Run Code Online (Sandbox Code Playgroud)
这是使用该文件共享文件的代码,FileProvider但不适用于任何应用程序,除非是最新的:
final File tmpFile = new File(context.getCacheDir(), "exported.jpg");
Uri tmpFileUri = FileProvider.getUriForFile(context, context.getPackageName() + ".fileprovider", tmpFile);
//Remove the uri permission because we overwrite …Run Code Online (Sandbox Code Playgroud)