Skip to content

Instantly share code, notes, and snippets.

JianGuo Yang lgyjg

View GitHub Profile
View YUV2RGB.cpp
static inline uint32_t YUV2RGB(int nY, int nU, int nV) {
nY -= 16;
nU -= 128;
nV -= 128;
if (nY < 0) nY = 0;
// This is the floating point equivalent. We do the conversion in integer
// because some Android devices do not have floating point in hardware.
// nR = (int)(1.164 * nY + 1.596 * nV);
// nG = (int)(1.164 * nY - 0.813 * nV - 0.391 * nU);
@lgyjg
lgyjg / CameraStreamConfigurations.java
Last active Aug 17, 2018
get CustomStreamConfigurationMap with a custom CameraCharacteristics Key
View CameraStreamConfigurations.java
package com.example.util;
import android.annotation.SuppressLint;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.params.StreamConfigurationMap;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
View HtmlToPDF.java
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.itextpdf.text.Document;
View LogBigBitmap.java
public static int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
@lgyjg
lgyjg / FibonacciView.java
Last active Apr 28, 2017
用点绘制黄金螺旋线
View FibonacciView.java
private void drawWithPoint(Canvas canvas, int deep) {
float x0 = this.getMeasuredWidth() / 2;
float y0 = this.getMeasuredHeight() / 2;
paint.setColor(Color.BLACK);
for (int i = 0; i < 6145; i++) {
double angle = i * Math.PI / 512;
double radius = 0.3 * angle;
int y = (int) Math.round(radius * angle * Math.cos(angle));
int x = (int) Math.round(radius * angle * Math.sin(angle));
canvas.drawPoint(x0 + x, y0 + y, paint);
@lgyjg
lgyjg / gist:381b48734a6b8d9fd62fa00898d54d4c
Created Apr 15, 2017
获取手机号码\获取手机运营商
View gist:381b48734a6b8d9fd62fa00898d54d4c
public class SIMCardInfo {
/**
* TelephonyManager提供设备上获取通讯服务信息的入口。 应用程序可以使用这个类方法确定的电信服务商和国家以及某些类型的用户访问信息。
* 应用程序也可以注册一个监听器到电话收状态的变化。不需要直接实例化这个类
* 使用Context.getSystemService(Context.TELEPHONY_SERVICE)来获取这个类的实例。
*/
private TelephonyManager telephonyManager;
/**
* 国际移动用户识别码
*/
@lgyjg
lgyjg / translation_replace.sh
Created Jun 12, 2016
批量替换文件中的字符串的shell脚本命令
View translation_replace.sh
#restore_cancel 代表需要过滤的字符串关键字
# <string name="restore_cancel">@android:string\/cancel<\/string>/g 代表含有该关键字字符串的行该替换成什么样.
# res 代表查找路径
sed -i 's/^.*restore_cancel.*$/ <string name="restore_cancel">@android:string\/cancel<\/string>/g' `grep restore_cancel -rl res`
@lgyjg
lgyjg / SaveBitmap.java
Last active Apr 28, 2017
save bitmap object to sdcard to test
View SaveBitmap.java
// need permission
// <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
// <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
public void saveMyBitmap(Bitmap mBitmap,String bitName) {
File f = new File( "/sdcard/Test/"+bitName + ".jpg");
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream(f);
mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
@lgyjg
lgyjg / gist:c65460bc3c9f17b4fc8a9839a04753ad
Last active Oct 30, 2017
java 实现 Bitmap 转 YUV 数据
View gist:c65460bc3c9f17b4fc8a9839a04753ad
/**
* YUV420sp
*
* @param inputWidth
* @param inputHeight
* @param scaled
* @return
*/
public static byte[] getYUV420sp(int inputWidth, int inputHeight, Bitmap scaled) {
Log.d(TAG, "getYUV420sp: start");
You can’t perform that action at this time.