我的应用程序可以从库中选择照片.我想要从这个选择中获取文件路径.
这是创建选择照片的意图的代码:
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, INTENT_REQUEST_CODE_SELECT_PHOTO);
Run Code Online (Sandbox Code Playgroud)
这是从URI获取文件路径的代码:
Cursor cursor = null;
String path = null;
try {
String[] projection = { MediaStore.Images.Media.DATA };
cursor = context.getContentResolver().query(contentUri, projection, null, null, null);
int columnIndex = cursor.getColumnIndexOrThrow(projection[0]);
cursor.moveToFirst();
path = cursor.getString(columnIndex);
} finally {
if (cursor != null) {
cursor.close();
}
}
return path;
Run Code Online (Sandbox Code Playgroud)
在昨天更新Google相册应用之前,一切都运转良好.path解析URI后现在为null.
URI类似于: content://com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F75209/ACTUAL
我还试图用Intent.ACTION_GET_CONTENT动作创建意图 - 没有运气.
我正在尝试使用类似Multiply的混合模式将两个图像与Android混合在一起.
// Prepare -------------------------------
// Create source images
Bitmap img1 = ...
Bitmap img2 = ...
// Create result image
Bitmap result = ...
Canvas canvas = new Canvas();
canvas.setBitmap(result);
// Get proper display reference
BitmapDrawable drawable = new BitmapDrawable(getResources(), result);
ImageView imageView = (ImageView)findViewById(R.id.imageBlend1);
imageView.setImageDrawable(drawable);
// Apply -------------------------------
// Draw base
canvas.drawBitmap(img1, 0, 0, null);
// Draw overlay
Paint paint = new Paint();
paint.setXfermode(new PorterDuffXfermode(Mode.MULTIPLY));
paint.setShader(new BitmapShader(img2, TileMode.CLAMP, TileMode.CLAMP));
canvas.drawRect(0, 0, img2.getWidth(), img2.getHeight(), paint);
Run Code Online (Sandbox Code Playgroud)
这是有效的,但是我无法控制所做的乘法"量" - 它始终是一个完全的乘法传递.理想情况下,0%乘法与基本图像(img1)相同而没有任何变化,但100%乘法将是我得到的上述代码的结果.
paint.setAlpha() 似乎不适用于此. …
有趣的事情 - 我一直关闭模拟器的窗口(右上角的X,是的)关闭它.
现在我感到有兴趣,如果在此期间模拟器中没有任何损坏.
令人惊讶的是,没有任何东西可以用Google搜索.
我正在尝试用 Kotlin 语言为我的 android 项目实现一些特定的 GSON TypeAdapter。
我面临的问题是编译错误,无法推断类型:Type inference failed: 'T' cannot capture 'in (T..T?'. Type parameter has an upper bound 'Enum<T>' that cannot be satisfied capturing 'in' projection
代码如下:
class SmartEnumTypeAdapterFactory(fallbackKey: String) : TypeAdapterFactory {
private val fallbackKey = fallbackKey.toLowerCase(Locale.US)
override fun <T : Any> create(gson: Gson?, type: TypeToken<T>): TypeAdapter<T>? {
val rawType = type.rawType
return if (!rawType.isEnum) null else SmartEnumTypeAdapter(rawType)
}
class SmartEnumTypeAdapter<T : Enum<T>>(classOfT: Class<T>) : TypeAdapter<T>() {
override fun write(out: JsonWriter?, value: T) {
TODO("not …Run Code Online (Sandbox Code Playgroud) 我正在实现注释处理库,该库使用基于具有特定注释的类的 java 诗人生成代码。
为了使用 kotlin 编写的类,我在示例项目中切换到 kapt 而不是 apt。它适用于带注释的 java 类就好了。Bun kotlin 类有一种不同的方法来访问类字段:应该使用 getter 和 setter。
有没有办法确定给定的类(更具体地说 - 不是类而是 TypeElement - 因为这是在编译之前发生的)是 java-class 还是用 kotlin 编写的?基于此,我可以编写生成字段访问或 getter-used 访问的代码。
android ×4
blending ×2
kotlin ×2
colors ×1
genymotion ×1
gson ×1
imagemagick ×1
java ×1
kapt ×1
photoshop ×1
porter-duff ×1