Search in sources :

Example 6 with SandPhoto

use of com.yydcdut.note.entity.SandPhoto in project PhotoNoter by yydcdut.

the class SandBoxServicePresenterImpl method makePhoto.

/**
     * 做图
     *
     * @param sandPhoto
     */
private void makePhoto(SandPhoto sandPhoto) {
    byte[] rowData = getDataFromFile(sandPhoto.getFileName(), sandPhoto.getSize());
    if (rowData == null) {
        return;
    }
    byte[] data;
    if (sandPhoto.getImageFormat() == ImageFormat.JPEG) {
        data = rowData;
    } else {
        data = decodeNV21(rowData, sandPhoto.getSandExif().getImageWidth(), sandPhoto.getSandExif().getImageLength());
    }
    if (data == null) {
        return;
    }
    Bitmap bitmap = null;
    try {
        bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
    } catch (OutOfMemoryError e) {
        YLog.e(e);
    }
    String fileName = sandPhoto.getTime() + ".jpg";
    if (FilePathUtils.savePhoto(fileName, bitmap)) {
        FilePathUtils.saveSmallPhoto(fileName, bitmap);
    }
    PhotoNote photoNote = new PhotoNote(fileName, sandPhoto.getTime(), sandPhoto.getTime(), "", "", sandPhoto.getTime(), sandPhoto.getTime(), sandPhoto.getCategoryId());
    photoNote.setPaletteColor(Utils.getPaletteColor(bitmap));
    mRxPhotoNote.savePhotoNote(photoNote).subscribe(photoNote1 -> {
    }, (throwable -> YLog.e(throwable)));
    try {
        setExif(photoNote, sandPhoto.getSandExif(), sandPhoto.getCameraId(), sandPhoto.isMirror());
    } catch (IOException e) {
        YLog.e(e);
    }
    deleteFromDBAndSDCard(sandPhoto);
    //        bitmap.recycle();
    System.gc();
}
Also used : RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) PhotoNote(com.yydcdut.note.entity.PhotoNote) Context(android.content.Context) Rect(android.graphics.Rect) RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SandPhoto(com.yydcdut.note.entity.SandPhoto) BitmapFactory(android.graphics.BitmapFactory) ExifInterface(android.media.ExifInterface) Observable(rx.Observable) Inject(javax.inject.Inject) Const(com.yydcdut.note.utils.Const) RxSandBox(com.yydcdut.note.model.rx.RxSandBox) Handler(android.os.Handler) FilePathUtils(com.yydcdut.note.utils.FilePathUtils) Utils(com.yydcdut.note.utils.Utils) ImageFormat(android.graphics.ImageFormat) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SandExif(com.yydcdut.note.entity.SandExif) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Message(android.os.Message) Bitmap(android.graphics.Bitmap) YuvImage(android.graphics.YuvImage) ISandBoxServiceView(com.yydcdut.note.views.service.ISandBoxServiceView) PhotoNote(com.yydcdut.note.entity.PhotoNote) ISandBoxServicePresenter(com.yydcdut.note.presenters.service.ISandBoxServicePresenter) YLog(com.yydcdut.note.utils.YLog) IView(com.yydcdut.note.views.IView) InputStream(java.io.InputStream) Bitmap(android.graphics.Bitmap) IOException(java.io.IOException)

Example 7 with SandPhoto

use of com.yydcdut.note.entity.SandPhoto in project PhotoNoter by yydcdut.

the class SandBoxTest method testSave.

public void testSave() {
    SandPhoto sandPhoto = new SandPhoto(SandPhoto.ID_NULL, 1l, "0", 1, false, 1, "111", 11, ImageFormat.JPEG, new SandExif(0, "s", "ss", 0, 0, 0, 1, "1", "1"));
    mRxSandBox.saveOne(sandPhoto).subscribe(new Subscriber<SandPhoto>() {

        @Override
        public void onCompleted() {
            YLog.i("yuyidong", "onCompleted");
        }

        @Override
        public void onError(Throwable e) {
            YLog.i("yuyidong", "onError");
        }

        @Override
        public void onNext(SandPhoto sandPhoto) {
            YLog.i("yuyidong", sandPhoto.toString());
        }
    });
}
Also used : SandExif(com.yydcdut.note.entity.SandExif) SandPhoto(com.yydcdut.note.entity.SandPhoto)

Example 8 with SandPhoto

use of com.yydcdut.note.entity.SandPhoto in project PhotoNoter by yydcdut.

the class CameraServicePresenterImpl method makePhoto.

/**
     * 做图
     *
     * @param sandPhoto
     */
private void makePhoto(SandPhoto sandPhoto) {
    byte[] rowData = getDataFromFile(sandPhoto.getFileName(), sandPhoto.getSize());
    if (rowData == null) {
        return;
    }
    byte[] data;
    if (sandPhoto.getImageFormat() == ImageFormat.JPEG) {
        data = rowData;
    } else {
        data = decodeNV21(rowData, sandPhoto.getSandExif().getImageWidth(), sandPhoto.getSandExif().getImageLength());
    }
    if (data == null) {
        return;
    }
    Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
    String fileName = sandPhoto.getTime() + ".jpg";
    if (FilePathUtils.savePhoto(fileName, bitmap)) {
        FilePathUtils.saveSmallPhoto(fileName, bitmap);
    }
    PhotoNote photoNote = new PhotoNote(fileName, sandPhoto.getTime(), sandPhoto.getTime(), "", "", sandPhoto.getTime(), sandPhoto.getTime(), sandPhoto.getCategoryId());
    photoNote.setPaletteColor(Utils.getPaletteColor(bitmap));
    mRxPhotoNote.savePhotoNote(photoNote).subscribe(photoNote1 -> {
        try {
            setExif(photoNote, sandPhoto.getSandExif(), sandPhoto.getCameraId(), sandPhoto.isMirror());
        } catch (IOException e) {
            YLog.e(e);
        }
        deleteFromDBAndSDCard(sandPhoto);
        mCameraServiceView.sendBroadCast();
    }, (throwable -> YLog.e(throwable)));
    //todo bitmap可以重复利用?
    bitmap.recycle();
    System.gc();
}
Also used : RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) PhotoNote(com.yydcdut.note.entity.PhotoNote) Context(android.content.Context) Rect(android.graphics.Rect) RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SandPhoto(com.yydcdut.note.entity.SandPhoto) BitmapFactory(android.graphics.BitmapFactory) ExifInterface(android.media.ExifInterface) Inject(javax.inject.Inject) Const(com.yydcdut.note.utils.Const) RxSandBox(com.yydcdut.note.model.rx.RxSandBox) FilePathUtils(com.yydcdut.note.utils.FilePathUtils) Utils(com.yydcdut.note.utils.Utils) ICameraServiceView(com.yydcdut.note.views.service.ICameraServiceView) ImageFormat(android.graphics.ImageFormat) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SandExif(com.yydcdut.note.entity.SandExif) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Bitmap(android.graphics.Bitmap) YuvImage(android.graphics.YuvImage) ICameraServicePresenter(com.yydcdut.note.presenters.service.ICameraServicePresenter) PhotoNote(com.yydcdut.note.entity.PhotoNote) Queue(java.util.Queue) YLog(com.yydcdut.note.utils.YLog) IView(com.yydcdut.note.views.IView) InputStream(java.io.InputStream) Bitmap(android.graphics.Bitmap) IOException(java.io.IOException)

Aggregations

SandExif (com.yydcdut.note.entity.SandExif)8 SandPhoto (com.yydcdut.note.entity.SandPhoto)8 Context (android.content.Context)4 Bitmap (android.graphics.Bitmap)4 BitmapFactory (android.graphics.BitmapFactory)4 ImageFormat (android.graphics.ImageFormat)4 Rect (android.graphics.Rect)4 YuvImage (android.graphics.YuvImage)4 ExifInterface (android.media.ExifInterface)4 PhotoNote (com.yydcdut.note.entity.PhotoNote)4 RxPhotoNote (com.yydcdut.note.model.rx.RxPhotoNote)4 RxSandBox (com.yydcdut.note.model.rx.RxSandBox)4 Const (com.yydcdut.note.utils.Const)4 FilePathUtils (com.yydcdut.note.utils.FilePathUtils)4 Utils (com.yydcdut.note.utils.Utils)4 YLog (com.yydcdut.note.utils.YLog)4 IView (com.yydcdut.note.views.IView)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4