我想在ImageView中使用显示从相机拍摄的图像
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
Run Code Online (Sandbox Code Playgroud)
到目前为止,此工作正常,但在用户使用所选的相机应用程序拍摄照片后,会出现一个对话框(可能来自应用程序),询问是否保存或删除拍摄的照片(至少在Android 2.3和4.2上使用默认的相机应用程序).
我想跳过这个额外的对话框,直接在ImageView中显示图像(当调用onActivityResult时),因为这意味着用户需要额外的交互步骤,这是不必要的,因为他可以保存或删除照片.我的应用.
这可以使用简单的ACTION_IMAGE_CAPTURE Intent,还是需要更复杂的东西,比如Camera Preview和SurfaceView?
我创建了一个自定义TextView,我唯一做的就是在布局xml中放置一个"实例".这会导致应用程序崩溃并出现" Inflate Exception ":
这是完整的自定义类(实际上它还没有"自定义"......):
package com.example.TestApp;
...
public class MyTextView extends TextView {
public MyTextView (Context context) {
super(context);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec); }
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
}
Run Code Online (Sandbox Code Playgroud)
}
完整的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.example.TestApp.MyTextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, MyActivity"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
日志是:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.TestApp/com.example.TestApp.MyActivity}:
android.view.InflateException: Binary XML file line #8: Error inflating class
com.example.TestApp.MyTextView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at …Run Code Online (Sandbox Code Playgroud) 是否可以通过在运行时编译的代码片段来提供接口的实现?
以下不起作用(安全类型转换返回"null"):
一个完整的控制台应用
using System;
using System.Collections.Generic;
namespace Foo
{
using System.CodeDom.Compiler;
using Microsoft.CSharp;
class Program
{
static void Main(string[] args)
{
// code snippet to compile:
string source =@"namespace Foo {
public class Test:ITest
{
public void Write()
{
System.Console.WriteLine(""Hello World"");
}
}
public interface ITest
{
void Write();
}
}
";//end snippet
// the "real" code:
Dictionary<string, string> providerOptions = new Dictionary<string, string>
{
{"CompilerVersion", "v4.0"}
};
CSharpCodeProvider provider = new CSharpCodeProvider(providerOptions);
CompilerParameters compilerParams = new CompilerParameters
{ …Run Code Online (Sandbox Code Playgroud) 我有一个"包含"文本的字节数组 - 此时编码/字符集是未知的.
如何在不从字节数组创建String对象的情况下删除空格,\n,\ r \n字符?
目标是将字节数组显示为文本,并使用用户指定的字符集,只是没有这些空格,\n,\ r \n字符.