Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
linhaojian committed Sep 19, 2018
1 parent 31dc9d8 commit 77135bb
Show file tree
Hide file tree
Showing 105 changed files with 284 additions and 21,575 deletions.
Binary file modified .gradle/4.4/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/4.4/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/4.4/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/4.4/javaCompile/classAnalysis.bin
Binary file not shown.
Binary file modified .gradle/4.4/javaCompile/jarAnalysis.bin
Binary file not shown.
Binary file modified .gradle/4.4/javaCompile/javaCompile.lock
Binary file not shown.
Binary file modified .gradle/4.4/javaCompile/taskHistory.bin
Binary file not shown.
Binary file modified .gradle/4.4/javaCompile/taskJars.bin
Binary file not shown.
Binary file modified .gradle/4.4/taskHistory/taskHistory.bin
Binary file not shown.
Binary file modified .gradle/4.4/taskHistory/taskHistory.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
1 change: 0 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/libraries/Gradle__com_android_support_design_28_0_0_rc02.xml

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

286 changes: 208 additions & 78 deletions .idea/workspace.xml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@
<orderEntry type="library" name="Gradle: com.android.support:customview-28.0.0-rc02" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:coordinatorlayout-28.0.0-rc02" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:support-core-utils-28.0.0-rc02" level="project" />
<orderEntry type="module" module-name="utilcode" />
<orderEntry type="module" module-name="bitmapprocess" />
</component>
</module>
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ dependencies {
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation project(':bitmapprocess')
implementation project(':utilcode')
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.LogUtils;
import com.lhj.bitmapprocess.BitmapCompressUtil;
import com.lhj.bitmapprocess.BitmapUtil;

import java.io.ByteArrayOutputStream;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
Expand Down Expand Up @@ -69,7 +66,7 @@ public void onClick(View view){

private void print(){
imageView.setImageBitmap(bitmap);
tv.setText("图片大小:"+ (bitmap.getByteCount() / 1024 / 1024)+"M"+
tv.setText("图片大小:"+ (bitmap.getByteCount() / 1024)+"KB"+
" 图片宽度:"+bitmap.getWidth()+
" 图片高度:"+bitmap.getHeight());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.lhj.bitmapprocess.test;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;

import com.blankj.utilcode.util.ActivityUtils;

import butterknife.BindView;
import butterknife.BindViews;
import butterknife.ButterKnife;
import butterknife.OnClick;

Expand All @@ -23,7 +19,8 @@ protected void onCreate(Bundle savedInstanceState) {

@OnClick(R.id.button2)
public void turnCompress(){
ActivityUtils.startActivity(this,CompressActivity.class);
Intent intent = new Intent(this,CompressActivity.class);
startActivity(intent);
}


Expand Down
71 changes: 71 additions & 0 deletions bitmapprocess/src/main/java/com/lhj/bitmapprocess/BitmapUtil.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,86 @@
package com.lhj.bitmapprocess;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.graphics.YuvImage;

import java.io.ByteArrayOutputStream;

public class BitmapUtil {

/**
* bitmap 转为byte[]
* @param bitmap
* @return
*/
public static byte[] getBytesByBitmap(Bitmap bitmap) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(bitmap.getByteCount());
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
return outputStream.toByteArray();
}

/**
* 在bitmap中进行指定位置截取
* @param bimtap
* @param rect
* @return
*/
public static Bitmap ImageCropWithRect(Bitmap bimtap, Rect rect){
return Bitmap.createBitmap(bimtap,rect.left,rect.top,rect.width(),rect.height(),null,false);
}

/**
* 将NV21的图片格式转换成bitmap
* @param bytes
* @param w
* @param h
* @return
*/
public static Bitmap nv21ToBitmap(byte[] bytes,int w,int h,int imageFormat){
final YuvImage image = new YuvImage(bytes,imageFormat , w, h, null);
ByteArrayOutputStream os = new ByteArrayOutputStream(bytes.length);
image.compressToJpeg(new Rect(0, 0, w, h), 100, os);
byte[] tmp = os.toByteArray();
return BitmapFactory.decodeByteArray(tmp, 0,tmp.length);
}

// untested function
public static byte[] bitmapToNV21(int inputWidth, int inputHeight, Bitmap scaled) {
int [] argb = new int[inputWidth * inputHeight];
scaled.getPixels(argb, 0, inputWidth, 0, 0, inputWidth, inputHeight);
byte [] yuv = new byte[inputWidth*inputHeight*2];
encodeYUV420SP(yuv, argb, inputWidth, inputHeight);
return yuv;
}

private static void encodeYUV420SP(byte[] yuv420sp, int[] argb, int width, int height) {
final int frameSize = width * height;
int yIndex = 0;
int uvIndex = frameSize;
int a, R, G, B, Y, U, V;
int index = 0;
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
a = (argb[index] & 0xff000000) >> 24; // a is not used obviously
R = (argb[index] & 0xff0000) >> 16;
G = (argb[index] & 0xff00) >> 8;
B = (argb[index] & 0xff) >> 0;
// well known RGB to YUV algorithm
Y = ( ( 66 * R + 129 * G + 25 * B + 128) >> 8) + 16;
U = ( ( -38 * R - 74 * G + 112 * B + 128) >> 8) + 128;
V = ( ( 112 * R - 94 * G - 18 * B + 128) >> 8) + 128;
// NV21 has a plane of Y and interleaved planes of VU each sampled by a factor of 2
// meaning for every 4 Y pixels there are 1 V and 1 U. Note the sampling is every other
// pixel AND every other scanline.
yuv420sp[yIndex++] = (byte) ((Y < 0) ? 0 : ((Y > 255) ? 255 : Y));
if (j % 2 == 0 && index % 2 == 0) {
yuv420sp[uvIndex++] = (byte)((V<0) ? 0 : ((V > 255) ? 255 : V));
yuv420sp[uvIndex++] = (byte)((U<0) ? 0 : ((U > 255) ? 255 : U));
}
index ++;
}
}
}

}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':app', ':bitmapprocess',':utilcode'
include ':app', ':bitmapprocess'
2 changes: 0 additions & 2 deletions utilcode/.gitignore

This file was deleted.

52 changes: 0 additions & 52 deletions utilcode/build.gradle

This file was deleted.

21 changes: 0 additions & 21 deletions utilcode/proguard-rules.pro

This file was deleted.

10 changes: 0 additions & 10 deletions utilcode/project.properties

This file was deleted.

1 change: 0 additions & 1 deletion utilcode/src/main/AndroidManifest.xml

This file was deleted.

This file was deleted.

Loading

0 comments on commit 77135bb

Please sign in to comment.