原来。。。

博客内容提及曾在此处开设博客并撰写文章。
原来我还在这里开过博客啊。。。还写过文章。。。
使用 UCrop 进行截图后替换原来图片,可以按照以下步骤实现。首先,需要获取原始图片的 `Uri`,然后指定裁剪后图片的保存位置,接着进行裁剪操作,最后将裁剪后的图片替换原来的图片。 以下是一个示例代码: ```java // 获取原始图片的 Uri Uri sourceUri = Uri.parse("file://" + originalImagePath); // 获取裁剪后图片保存的路径并转换为 Uri Uri destinationUri = Uri.parse(new WeplayPathManager().getSaveCropImageUrl()); // 创建 UCrop 实例 UCrop uCrop = UCrop.of(sourceUri, destinationUri); // 设置裁剪选项 UCrop.Options options = new UCrop.Options(); options.setAllowedGestures(UCropActivity.SCALE, UCropActivity.ROTATE, UCropActivity.ALL); uCrop.withOptions(options); // 启动裁剪界面 uCrop.start(this); // 在 onActivityResult 方法中处理裁剪结果 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK && requestCode == UCrop.REQUEST_CROP) { final Uri resultUri = UCrop.getOutput(data); // 将裁剪后的图片替换原来的图片 try { InputStream inputStream = getContentResolver().openInputStream(resultUri); FileOutputStream outputStream = new FileOutputStream(new File(originalImagePath)); byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } inputStream.close(); outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } else if (resultCode == UCrop.RESULT_ERROR) { final Throwable cropError = UCrop.getError(data); } } ``` 在上述代码中,首先通过 `UCrop.of()` 方法创建裁剪实例,设置裁剪选项后启动裁剪界面。在 `onActivityResult` 方法中,当裁剪成功时,获取裁剪后的图片 `Uri`,然后将裁剪后的图片内容复制到原来图片的位置,从而实现替换操作。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值