Android 如何显示存储在我的应用程序目录中的svg图像
我想显示存储在我的应用程序目录中的Svg图像我写了一个代码,显示存储在drawable文件夹中的图像,但我想显示我的应用程序目录中的图像以及存储在“Android/data/QR.Android/files/Q317664.Svg”中的图像Android 如何显示存储在我的应用程序目录中的svg图像,android,image,svg,xamarin,filepath,Android,Image,Svg,Xamarin,Filepath,我想显示存储在我的应用程序目录中的Svg图像我写了一个代码,显示存储在drawable文件夹中的图像,但我想显示我的应用程序目录中的图像以及存储在“Android/data/QR.Android/files/Q317664.Svg”中的图像 使用系统; 使用System.Linq; 运用系统反思; 使用Android.App; 使用Android.Content; 使用Android.Runtime; 使用Android.Views; 使用Android.Widget; 使用Android.OS
使用系统;
使用System.Linq;
运用系统反思;
使用Android.App;
使用Android.Content;
使用Android.Runtime;
使用Android.Views;
使用Android.Widget;
使用Android.OS;
使用XamSvg;
使用Android.Graphics;
名称空间QR.Android
{
[Activity(Label=“Activity3”,Theme=“@android:style/Theme.Holo.Light.NoActionBar.Fullscreen”)]
公共课堂活动3:活动
{
int[]rawIds;
int[]可绘制视图ID;
私有字符串[]共享名称;
int currentId;
创建时受保护的覆盖无效(捆绑包)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.layout1);
//初始化跨平台颜色帮助器
Setup.InitSvgLib();
//当使用“res:”时,告诉XamSvg在哪个程序集中搜索svg
var assembly=typeof(AppDomain).GetTypeInfo().assembly;
XamSvg.Shared.Config.ResourceAssembly=程序集;
//获取原始文件夹中的所有svg资源ID
rawIds=typeof(Resource.Drawable)
.GetFields()
.其中(f=>f.IsLiteral)
.Select(f=>(int)f.GetRawConstantValue()
.ToArray();
//获取当前布局中的所有图形分区
DrawableViewId=typeof(Resource.Id)
.GetFields()
.Where(f=>f.IsLiteral&&f.Name.StartsWith(“可绘制”))
.Select(f=>(int)f.GetRawConstantValue()
.ToArray();
//获取共享程序集中的所有svg资源
sharedNames=assembly.GetManifestResourceNames().Where(n=>n.EndsWith(“.svg”).OrderBy(n=>n.ToArray();
//单击时,更改所有区域中的svg源
var contentView=findviewbyd(Resource.Id.content);
currentId=currentId+2;
contentView。单击+=(发件人,e)=>
{
if(当前ID<原始长度)
LoadImageTest(rawIds[currentId]);
//否则
//LoadImageTest(sharedNames[currentId rawIds.Length]);
//currentId=(++currentId)%(rawIds.Length+sharedNames.Length);
};
LoadImageTest(rawIds[currentId++]);
}
无效载荷图像测试(int rawId)
{
foreach(DrawableViewId中的var drawableId)
{
//if(drawableID!=Resource.Id.drawable100)
//继续;
var v=FindViewById(可提取ID);
var drawable=SvgFactory.GetDrawable(资源,rawId);
v、 可设置图像可绘制(可绘制);
}
}
}
}
试试免费的Xam.Plugins.Forms.Svg插件我如何使用这个插件请给我举个例子。此插件的存储库中有一个示例
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/content"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="8dp">
<LinearLayout
android:orientation="horizontal"
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="16dp"
android:gravity="center_horizontal">
<XamSvg.SvgImageView
android:id="@+id/icon"
local:svg="res:images.0Password"
android:layout_width="fill_parent"
android:layout_height="40dp" />
</LinearLayout>
<ImageView
android:src="@android:drawable/ic_menu_gallery"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/drawableAutoSize"
android:scaleType="fitCenter"
android:background="#AAD39F" />
</LinearLayout>
using System;
using System.Linq;
using System.Reflection;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using XamSvg;
using Android.Graphics;
namespace QR.Android
{
[Activity(Label = "Activity3",Theme = "@android:style/Theme.Holo.Light.NoActionBar.Fullscreen")]
public class Activity3 : Activity
{
int[] rawIds;
int[] drawableViewIds;
private string[] sharedNames;
int currentId;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.layout1);
//Initialize the cross platform color helper
Setup.InitSvgLib();
//Tells XamSvg in which assembly to search for svg when "res:" is used
var assembly = typeof(AppDomain).GetTypeInfo().Assembly;
XamSvg.Shared.Config.ResourceAssembly = assembly;
//Get all svg resource ids in the raw folder
rawIds = typeof(Resource.Drawable)
.GetFields()
.Where(f => f.IsLiteral)
.Select(f => (int)f.GetRawConstantValue())
.ToArray();
//Get all drawing zones in the current layout
drawableViewIds = typeof(Resource.Id)
.GetFields()
.Where(f => f.IsLiteral && f.Name.StartsWith("drawable"))
.Select(f => (int)f.GetRawConstantValue())
.ToArray();
//Get all svg resources in the shared assembly
sharedNames = assembly.GetManifestResourceNames().Where(n => n.EndsWith(".svg")).OrderBy(n => n).ToArray();
//When clicked, change the svg source in all zones
var contentView = FindViewById(Resource.Id.content);
currentId = currentId + 2;
contentView.Click += (sender, e) =>
{
if (currentId < rawIds.Length)
LoadImageTest(rawIds[currentId]);
// else
// LoadImageTest(sharedNames[currentId-rawIds.Length]);
// currentId = (++currentId)%(rawIds.Length+sharedNames.Length);
};
LoadImageTest(rawIds[currentId++]);
}
void LoadImageTest(int rawId)
{
foreach (var drawableId in drawableViewIds)
{
// if (drawableID != Resource.Id.drawable100)
// continue;
var v = FindViewById<ImageView>(drawableId);
var drawable = SvgFactory.GetDrawable(Resources, rawId);
v.SetImageDrawable(drawable);
}
}
}
}