Skip to content

Commit

Permalink
add timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
JinghaoZhao committed Aug 6, 2019
1 parent bfa0e76 commit 9c6091b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 38 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/me/pqpo/smartcamera/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ protected void onProgressUpdate(String... values) {
// // notify the adapter that the data set has changed. This means that new message received
// // from server was added to the list
// mAdapter.notifyDataSetChanged();
new ImgThread(mCameraView,mTcpClient).start();
new ImgThread(mCameraView,mTcpClient,values[0]).start();

}
}
Expand Down
36 changes: 33 additions & 3 deletions smartcameralib/src/main/java/me/pqpo/smartcameralib/ImgThread.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package me.pqpo.smartcameralib;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Environment;
import android.util.Base64;
import android.util.Log;
Expand All @@ -19,6 +22,7 @@ public class ImgThread extends Thread{
private Size size;
private TCPClient myTcpClient;
private SmartCameraView camera;
private String timestamp;


// public ImgThread(byte[] data, Size size, TCPClient mTcpClient){
Expand All @@ -27,18 +31,44 @@ public class ImgThread extends Thread{
// this.myTcpClient = mTcpClient;
// }

public ImgThread(SmartCameraView smartCameraView, TCPClient mTcpClient){
public ImgThread(SmartCameraView smartCameraView, TCPClient mTcpClient, String timestamp){
this.camera = smartCameraView;
this.myTcpClient = mTcpClient;
this.timestamp = timestamp;
}

@Override
public void run() {
// Bitmap bm = rawByteArray2RGBABitmap2(this.data, this.size.getWidth(), this.size.getHeight());
size = camera.getSizenow();
Bitmap bm = rawByteArray2RGBABitmap2(camera.getDatanow(), size.getWidth(), size.getHeight());
int width = size.getWidth();
int height = size.getHeight();

int dstWidth = 1920;
int dstHeight = 1080;

Bitmap bm = rawByteArray2RGBABitmap2(camera.getDatanow(), width, height);

bm = Bitmap.createScaledBitmap(bm, dstWidth, dstHeight, true);

//add the timestamp
Canvas canvas=new Canvas(bm);//创建一个空画布,并给画布设置位图
Paint p=new Paint();

p.setColor(Color.WHITE); //设置画笔颜色
p.setStyle(Paint.Style.FILL); //设置画笔模式为填充
p.setStrokeWidth(10f); //设置画笔宽度为10px
canvas.drawRect(Math.round(dstWidth * 3 / 4),Math.round(dstHeight * 3 / 4),width,height,p);


p.setColor(Color.BLACK);//设置画笔颜色
p.setAntiAlias(true);//抗锯齿
p.setTextSize(60);//设置字体大小
canvas.drawText(this.timestamp,Math.round(dstWidth * 3 / 4) + 20,Math.round(dstHeight * 3 / 4)+130,p);//在画布上绘制文字,即在位图上绘制文字

Log.e("width:",Integer.toString(Math.round(dstWidth * 3 / 4)));
Log.e("height:",Integer.toString(Math.round(dstHeight * 3 / 4)));

bm = Bitmap.createScaledBitmap(bm, 1920, 1080, true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object
byte[] b = baos.toByteArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,40 +113,40 @@ public void onPicturePreview(CameraImpl camera, byte[] data) {
});
}

public static class connectTask extends AsyncTask<String,String, TCPClient> {

@Override
protected TCPClient doInBackground(String... message) {

//we create a TCPClient object and
mTcpClient = new TCPClient(new TCPClient.OnMessageReceived() {
@Override
//here the messageReceived method is implemented
public void messageReceived(String message) {
//this method calls the onProgressUpdate
publishProgress(message);
// Log.e("tcpReceived3", message);
}
});
mTcpClient.run();

return null;
}

@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
Log.e("tcpReceived2", values[0]);

// new Thread(new Runnable() {
// public static class connectTask extends AsyncTask<String,String, TCPClient> {
//
// @Override
// protected TCPClient doInBackground(String... message) {
//
// //we create a TCPClient object and
// mTcpClient = new TCPClient(new TCPClient.OnMessageReceived() {
// @Override
// public void run() {
// mTcpClient.sendMessage("6666");
// //here the messageReceived method is implemented
// public void messageReceived(String message) {
// //this method calls the onProgressUpdate
// publishProgress(message);
//// Log.e("tcpReceived3", message);
// }
// }).start();

}
}
// });
// mTcpClient.run();
//
// return null;
// }
//
// @Override
// protected void onProgressUpdate(String... values) {
// super.onProgressUpdate(values);
// Log.e("tcpReceived2", values[0]);
//
//// new Thread(new Runnable() {
//// @Override
//// public void run() {
//// mTcpClient.sendMessage("6666");
//// }
//// }).start();
//
// }
// }

public Bitmap rawByteArray2RGBABitmap2(byte[] data, int width, int height) {
int frameSize = width * height;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public TCPClient(OnMessageReceived listener) {
*/
public void sendMessage(String message){
if (out != null && !out.checkError()) {
Log.e("Send Msg",message);
Log.e("Send Msg Length",Integer.toString(message.length()));
// Log.e("Send Msg",message);
// Log.e("Send Msg Length",Integer.toString(message.length()));
out.println(message);
out.flush();

Expand Down

0 comments on commit 9c6091b

Please sign in to comment.