android - Rotate image left/right as we can do in gallery and save -
i trying rotate image left/right can in gallery , saving it, problem losing quality , when open gallery, thumbnail of rotated image show original(not rotated) , when open image see original image (not rotated) , after seconds gallery loads rotated image.
ideally how should happen, can check in gallery, try rotated image, can see thumbnail rotated properly.
in short want rotate image left/right see in gallery. please needful.
i tried many solutions
what have done
when user clicks rotate left/right icon in app execute code
private void writerotatedbitmap(float angle) { try { file file = new file(sheetpaths.get(count)); bitmap bmp = bitmapfactory.decodefile(sheetpaths.get(count)); matrix matrix = new matrix(); matrix.postrotate(angle); bmp = bitmap.createbitmap(bmp, 0, 0, bmp.getwidth(), bmp.getheight(), matrix, true); fileoutputstream out; out = new fileoutputstream(file); bmp.compress(bitmap.compressformat.jpg, 90, out); out.flush(); out.close(); bmp = null; } catch (filenotfoundexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } }
download cropimage .
bitmap mbitmap; // initialize
// rotate left
mbitmap = util.rotateimage(mbitmap, -90); rotatebitmap rotatebitmap = new rotatebitmap(mbitmap); mimageview.setimagerotatebitmapresetbase(rotatebitmap, true);
// rotate right
mbitmap = util.rotateimage(mbitmap, 90); rotatebitmap rotatebitmap = new rotatebitmap(mbitmap); mimageview.setimagerotatebitmapresetbase(rotatebitmap, true);
edit
// rotate right
your_image_view.setimagebitmap(rotateimage(bitmapfactory.decoderesource(getresources(), r.drawable.image),90));
// rotate left
your_image_view.setimagebitmap(rotateimage(bitmapfactory.decoderesource(getresources(), r.drawable.image),-90));
and
public bitmap rotateimage(bitmap src, float degree) { // create new matrix object matrix matrix = new matrix(); // setup rotation degree matrix.postrotate(degree); // return new bitmap rotated using matrix return bitmap.createbitmap(src, 0, 0, src.getwidth(), src.getheight(), matrix, true); }
Comments
Post a Comment