package com.libsvg;
/**
*
* @author Pavel.B.Chernov (based on ideas of kushnarev)
*
*/
import com.ImageViewSvg.R;
import android.graphics.drawable.Drawable;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.ImageView;
import org.apache.http.util.EncodingUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
/**
* A Drawable that wraps an Svg image and can be stretched or aligned. You can create a
* SvgDrawable from a file path, an input stream, through XML inflation.
* <p>It can be defined in an XML file with the <code><com.libsvg.SvgDrawable></code> element.</p>
* <p>
* Also see the {@link com.libsvg.SvgImageView} class, which cares about loading and operating
* with svg graphics inside view container.
* </p>
*
* @attr ref android.R.styleable#SvgDrawable_src
* @attr ref android.R.styleable#SvgDrawable_antialias
* @attr ref android.R.styleable#SvgDrawable_filter
* @attr ref android.R.styleable#SvgDrawable_dither
* @attr ref android.R.styleable#SvgDrawable_gravity
*/
public class SvgDrawable extends Drawable {
private static final int DEFAULT_PAINT_FLAGS = Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG;
// Load native libraries
static {
System.loadLibrary("svgandroid");
}
// libsvg-android rasterizer id
private long mSvgId;
private Bitmap mBitmap;
private int mGravity = Gravity.FILL;
private Paint mPaint = new Paint(DEFAULT_PAINT_FLAGS);
// These are scaled to match the target density.
private int mWidth = -1;
private int mHeight = -1;
private double mOriginalAspectRatio = 1.0;
private final Rect mDstRect = new Rect(); // Gravity.apply() sets this
private boolean mApplyGravity;
private ImageView.ScaleType mScaleType = ImageView.ScaleType.FIT_CENTER;
// TODO
// Native libsvgandroid SHOULD USE this value to calculate width and height in pixels
// Because size in SVG image can be written in mm, cm, inches, feets ....
private float mRealDPI = 0;
/**
* Creates a new SvgDrawable object and loads SVG by resource ID
*/
static public SvgDrawable getDrawable(Resources res, int id) {
InputStream inStream = res.openRawResource(id);
if (inStream == null) {
return null;
}
SvgDrawable obj = new SvgDrawable(res, inStream);
return obj;
}
/**
* Create an empty drawable, not dealing with density.
* @deprecated Use {@link #SvgDrawable(Resources)} to ensure
* that the drawable has correctly set its target density.
*/
@Deprecated
public SvgDrawable() {
}
/**
* Create an empty drawable.
*/
public SvgDrawable(Resources res) {
if (res != null) {
mRealDPI = (res.getDisplayMetrics().xdpi + res.getDisplayMetrics().ydpi) / 2;
}
}
/**
* Create a drawable by opening a given file path and decoding the SVG.
* @throws FileNotFoundException
* @deprecated Use {@link #SvgDrawable(Resources, String)} to ensure
* that the drawable has correctly set its target density.
*/
@Deprecated
public SvgDrawable(String filepath) throws FileNotFoundException {
FileInputStream f = new FileInputStream(filepath);
LoadSvg(null, f);
}
/**
* Create a drawable by opening a given file path and decoding the bitmap.
* @throws FileNotFoundException
*/
public SvgDrawable(Resources res, String filepath) throws FileNotFoundException {
FileInputStream f = new FileInputStream(filepath);
LoadSvg(res, f);
}
/**
* Create a drawable by decoding SVG from the given input stream.
* @deprecated Use {@link #SvgDrawable(Resources, java.io.InputStream)} to ensure
* that the drawable has correctly set its target density.
*/
@Deprecated
public SvgDrawable(java.io.InputStream is) {
LoadSvg(null, is);
}
/**
* Create a drawable by decoding a bitmap from the given input stream.
*/
public SvgDrawable(Resources res, java.io.InputStream is) {
LoadSvg(res, is);
}
/**
* Decodes a drawable from the given input stream.
*/
public boolean LoadSvg(Resources res, java.io.InputStream is) {
try {
if (res != null) {
// TODO
mRealDPI = (res.getDisplayMetrics().xdpi + res.getDisplayMetrics().ydpi) / 2;
}
// Read into the buffer
if (is != null) {
byte[] buffer = new byte[is.available()];
is.read(buffer);
is.close();
// And make a string
String content = EncodingUtils.getString(buffer, "UTF-8");
buffer = null;
// Parse it
mSvgId = SvgRaster.svgAndroidCreate();
if (SvgRaster.svgAndroidParseBuffer(mSvgId, content) != 0) {
android.util.Log.w("SvgDrawable", "SvgDrawable cannot decode " + is);
}
SvgRaster.svgAndroidSetAntialiasing(mSvgId, true);
mWidth = SvgRaster.svgAndroidGetWidth(mSvgId);
mHeight = SvgRaster.svgAndroidGetHeight(mSvgId);
mOriginalAspectRatio = ((double)mWidth) / ((double)mHeight);
return true;
}
}
catch (IOException e) {
e.printStackTrace();
}
return false;
}
public final Paint getPaint() {
return mPaint;
}
public final Bitmap getBitmap() {
return mBitmap;
}
/** Get the gravity used to position/stretch the bitmap within its bounds.
* See android.view.Gravity
* @return the gravity applied to the bitmap
*/
public int getGravity() {
return mGravity;
}
/** Set the gravity used to position/stretch the bitmap within its bounds.
See android.view.Gravity
* @param gravity the gravity
*/
public void setGravity(int gravity) {
mApplyGravity = (mGravity != gravity);
mGravity = gravity;
}
public void setAntiAlias(boolean aa) {
com.libsvg.SvgRaster.svgAndroidSetAntialiasing(mSvgId, aa);
}
@Override
public void setFilterBitmap(boolean filter) {
mPaint.setFilterBitmap(filter);
}
@Override
public void setDither(boolean dither) {
mPaint.setDither(dither);
}
public void setScaleType(ImageView.ScaleType scaleType) {
mScaleType = scaleType;
invalidateSelf();
}
/*
* This is essential for correct transformation of SVG image
* It is called from SvgImageView.onSizeChanged , .setImageDrawable, .setScaleType
* Actual processing of scaleType is in private void ImageView.configureBounds()
* But this procedure is called before that.
* So we can adopt our width and height respectively to scaleType
*/
public void adjustToParentSize(int vWidth, int vHeight) {
// Reload original width and height
mWidth = SvgRaster.svgAndroidGetWidth(mSvgId);
mHeight = SvgRaster.svgAndroidGetHeight(mSvgId);
switch (mScaleType) {
case FIT_XY:
mWidth = vWidth;
mHeight = vHeight;
break;
case CENTER: // No scaling
break;
case CENTER_CROP: // Scale so that both width and height of the image will be equal to or larger than view
if (mWidth * vHeight > vWidth * mHeight) {
mHeight = vHeight;
mWidth = (int)(((double)mHeight) * mOriginalAspec
没有合适的资源?快使用搜索试试~ 我知道了~
android svg 的源码资源

共596个文件
h:176个
c:136个
d:104个


温馨提示
这是我从网上取下来的,因为那个网要注册,为方便网友,放到这里了。是android svg的资源http://www.codeproject.com/KB/android/Android_SVG_support/ImageViewSvg.zip 衷心感谢原作者
资源推荐
资源详情
资源评论





















收起资源包目录





































































































共 596 条
- 1
- 2
- 3
- 4
- 5
- 6

漂流的代码
- 粉丝: 189
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 【Android应用源码】自定义动画toast.zip
- 【Android应用源码】自动发送短信.zip
- 【Android应用源码】自动开关机实现.zip
- 永磁同步电机的5次7次电流谐波注入补偿Simulink模型仿真
- 现代密码学:理论与实践精华
- python定量数据扰乱
- python-新旧映射
- maven下载安装与配置教程.md
- 模拟IC技术:BlueCoreTM3-Flash与BlueCore3-Audio Flash集成电路特性解析及其应用
- 孤岛模式下双台逆变器下垂控制技术:确保电网频率与电压稳定
- maven下载安装与配置教程.md
- maven下载安装与配置教程.md
- 【Android应用源码】最全的OCR图像识别技术源码内有说明.zip
- 【Android应用源码】左右翻页翻书.zip
- maven下载安装与配置教程.md
- elasticsearch-6.6.2版本相关的压缩包
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制

- 1
- 2
前往页