标签: android-bitmap

Android 在 ImageView 上缩放、拖动、绘制

我在绘制和缩放 ImageView 时遇到问题。请帮帮我..

当我绘制一些东西然后拖动或缩放图像时 - 绘图保留在其位置,正如您在屏幕截图上看到的那样。我只需要在图片上绘制,并且可以缩放和拖动这张图片。

在此处输入图片说明 在此处输入图片说明

我有一个带有以下操作的自定义 ImageView:

 public class DrawingView extends ImageView {
// onTouch
private float mX, mY;
private static final float TOUCH_TOLERANCE = 4;

private Path mPath;

private boolean zoomEnabled = true;

private Paint drawPaint, canvasPaint;
//initial color
private int paintColor = 0xFF660000;
//canvas
private Canvas drawCanvas;
//canvas bitmap
private Bitmap canvasBitmap;

private static final int INVALID_POINTER_ID = -1;

private float mPosX;
private float mPosY;

private float mLastTouchX;
private float mLastTouchY;
private float mLastGestureX;
private float mLastGestureY; …
Run Code Online (Sandbox Code Playgroud)

android android-imageview android-canvas android-bitmap

6
推荐指数
1
解决办法
2641
查看次数

Retrofit 2下载图像并保存到文件夹

我需要从服务器下载图像并将其保存到文件夹,所以我使用的是Retrofit 2.

问题是,当我在文件夹中查找时,保存的图像为空,我尝试调试并看到Bitmap为空.

我不明白为什么,这是我的代码:

@GET("images/{userId}/{imageName}")
@Streaming
Call<ResponseBody> downloadImage(@Path("userId") String userId, @Path("imageName") String imageName);
Run Code Online (Sandbox Code Playgroud)

下载图片代码:

 private void downloadImage(final int position) {
    String url = "htttp://myserver.com/";
        retrofitImage = new Retrofit.Builder()
                .baseUrl(url)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

    imageApi = retrofitImage.create(BlastApiService.class);

    String userId = feedList.get(position).getUserId();
    String fileName = feedList.get(position).getFile();

    Call<ResponseBody> imageCall = imageApi.downloadImage(userId, fileName );
    imageCall.enqueue(new Callback<ResponseBody>() {
        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            if(response.isSuccess()){
                String fileName = feedList.get(position).getFile();
                InputStream is = response.body().byteStream();
                Bitmap bitmap = BitmapFactory.decodeStream(is);
                saveImage1(bitmap, fileName);
            } else{
                try {
                    Log.d("TAG", "response …
Run Code Online (Sandbox Code Playgroud)

android retrofit android-bitmap retrofit2

6
推荐指数
1
解决办法
6276
查看次数

如何才能第二次正确保存我的位图?

我想将我的位图保存到缓存目录.我用这个代码:

try {
        File file_d = new File(dir+"screenshot.jpg");
        @SuppressWarnings("unused")
        boolean deleted = file_d.delete();
    } catch (Exception e) {
        // TODO: handle exception
    }

    imagePath = new File(dir+"screenshot.jpg");
    FileOutputStream fos;
    try {
        fos = new FileOutputStream(imagePath);
        bitmap.compress(CompressFormat.JPEG, 100, fos);
        fos.flush();
        fos.close();
    } catch (FileNotFoundException e) {
        Log.e("GREC", e.getMessage(), e);
    } catch (IOException e) {
        Log.e("GREC", e.getMessage(), e);
    }
}
Run Code Online (Sandbox Code Playgroud)

它工作正常.但是,如果我想将不同的img保存到相同的路径,那么就会出现问题.我的意思是它被保存到相同的路径,但我看到它的旧图像,但当我点击图像,我可以看到我第二次保存的正确图像.

也许它来自缓存,但我不想看到旧图像,因为当我想与whatsapp旧图像共享该图像时,如果我发送图像似乎是正确的.

我想在whatsapp上分享已保存的图像,如下代码:

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(imagePath));
shareIntent.setType("image/jpeg");
startActivityForResult(Intent.createChooser(shareIntent, getResources().getText(R.string.title_share)),whtsapp_result);
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

提前致谢.

android android-layout android-imageview android-file android-bitmap

6
推荐指数
1
解决办法
303
查看次数

以编程方式创建图层列表

我试图以编程方式创建一个图层列表与调整大小的位图作为项目.从我所看到的BitmapDrawable已被弃用.新构造函数需要以下参数 - public BitmapDrawable(Resources res,Bitmap bitmap).我从下面的一个非常基本的例子开始.

    BitmapDrawable background = new BitmapDrawable();
    background.setBounds(10,10,10,10);
    Drawable[] layers = {background};
    LayerDrawable splash_test = new LayerDrawable(layers);
    splash_test.setLayerInset(0, 0, 0, 0, 0);
Run Code Online (Sandbox Code Playgroud)

我如何正确使用新的BitmapDrawable构造函数以及如何将可绘制资源链接到背景对象.

java android android-bitmap

6
推荐指数
1
解决办法
5423
查看次数

Android:我们可以使用 glide 压缩图像吗?

在发送到服务器之前,是否可以使用滑翔来压缩从图库中选取或由相机捕获的图像。

换句话说,可以像这样压缩图像:

1) 使用 glide 读取 uri 并更改为位图。

2) 检查位图的大小。

3) 使用 Bitmap.creatScaledBitmap(....) 调整位图的大小。

4) 位图质量较低。

5)然后发送。

是否可以?

如果我已经按照旧方式这样做,我会得到什么好处:

1) 从文件中获取位图。

2)与上面相同的东西......

谢谢。

android android-bitmap android-glide

6
推荐指数
0
解决办法
1049
查看次数

来自图库的图像会自动旋转 - Android

在我的Android应用程序中,我正在从设备库加载图像.在那,我面临着关于图像方向的问题.当我从图库中加载大分辨率图像时,它们会自动旋转,然后在我的视图中显示.我尝试了有关此问题的各种解决方案但无法得到正确的解决方案 我引用了getOrientation()这个链接.我已经尝试了两种解决方案,但无法获得理想的结果.ExifInterface返回正确的数据,但随后由于分辨率较大而不是因为相机方向而导致图像旋转,因此无效.请帮我解决这个问题.

谢谢.

android bitmap android-imageview bitmapfactory android-bitmap

5
推荐指数
2
解决办法
7948
查看次数

如何在android中组合叠加位图和捕获的图像?

我要求我需要创建一个自定义相机,并允许用户在捕获图像时放置徽标.徽标可以放大/缩小,并可在任何地方的摄像机视图中移动.我已经编写了以下代码来执行此操作,我能够成功放大/缩小并移动徽标图像,但是当我结合使用从相机拍摄的徽标和图片时,它没有正确组合.徽标图像放置在不同的位置,它的大小减少了.请有人帮助我,因为我已经卡在这里,无法找到问题所在.我还附上了手机中的截图供参考.请检查一下.

在点击捕获按钮之前,我已将徽标移动到左下角

在此输入图像描述

点击捕获按钮后,两个图像组合如下.

在此输入图像描述

public class CustomCamera extends Activity implements OnTouchListener,
    SurfaceHolder.Callback {

private Matrix matrix = new Matrix();
private Matrix savedMatrix = new Matrix();
private static final int NONE = 0;
private static final int DRAG = 1;
private static final int ZOOM = 2;
private int mode = NONE;
private PointF start = new PointF();
private PointF mid = new PointF();
private float oldDist = 1f;
private float d = 0f;
private float newRot = 0f;
private float[] lastEvent …
Run Code Online (Sandbox Code Playgroud)

android bitmap surfaceview android-camera android-bitmap

5
推荐指数
1
解决办法
3249
查看次数

如何在Android上的Glide中设置位图图像

SqliteDatabase我的应用程序中有一个.在此数据库中,我保存了StingBlob(用于保存图像).该图像以byte []保存在应用程序中.我借助以下代码将此图像转换为Bitmap:

    byte[] Recycler_imageByte;
    Bitmap Recycler_theImage;

holder.Recycler_imageByte = data.get(position).getKey_image();
ByteArrayInputStream imageStream = new ByteArrayInputStream(holder.Recycler_imageByte);
holder.Recycler_theImage = BitmapFactory.decodeStream(imageStream);
Run Code Online (Sandbox Code Playgroud)

我想在Glidelibary中显示这个图像,我编写了以下代码:

Glide.with(context).load(holder.Recycler_theImage).asBitmap().into(holder.Recycler_adapter_image);
Run Code Online (Sandbox Code Playgroud)

但是,当我运行应用程序时,会显示以下错误:

03-15 10:23:14.311 22440-22440/com.tellfa.dastanak E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.tellfa.dastanak, PID: 22440
java.lang.IllegalArgumentException: Unknown type class android.graphics.Bitmap. You must provide a Model of a type for which there is a registered ModelLoader, if you are using a custom model, you must first call Glide#register with a ModelLoaderFactory for your custom model class …
Run Code Online (Sandbox Code Playgroud)

android android-bitmap android-glide

5
推荐指数
2
解决办法
9358
查看次数

将照片上传到驱动器而不压缩

我想将相机中的照片直接上传到驱动器文件夹中:

OutputStream outputStream = result.getDriveContents().getOutputStream();
                    ByteArrayOutputStream bitmapStream = new ByteArrayOutputStream();
/* image is my Bitmap */
                    image.compress(Bitmap.CompressFormat.PNG, 100, bitmapStream);

                    try {
                        outputStream.write(bitmapStream.toByteArray());
                    } catch (IOException e1) {
                        Log.i(TAG, "Unable to write file contents.");
                    }
Run Code Online (Sandbox Code Playgroud)

所以我这样做,它的工作.问题是我在驱动器中的图片质量很差,我需要一个高质量的视频.

我已经尝试过这个解决方案将位图转换为byteArray android

但随后在驱动器中,照片无法识别为媒体文件,无法读取.我可能失败了.

编辑:我究竟做了同样的事情,是有/sf/answers/910054211/,做这种办法让我的位图ActivityResult:

try {
                    mBitmapToSave = MediaStore.Images.Media.getBitmap(this.getContentResolver(), data.getData());
                } catch (IOException e) {
                    e.printStackTrace();
                }
Run Code Online (Sandbox Code Playgroud)

android drive android-bitmap google-drive-android-api

5
推荐指数
1
解决办法
471
查看次数

如何有效地将位图对象读取为二维整数数组?

我需要在我的Android应用程序中将整个Bitmap对象读取为二维整数数组。

目前,我正在一次分别读取每个像素,如下所示:

for (int y = 0; y < coverImageHeight; y++)
{
    for (int x = 0; x < coverImageWidth; x++)
    {
        coverImageIntArray[x][y] = coverImageBitmap.getPixel(x, y);
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,这在大图像上会花费很长时间(大约15秒)。

有没有一种方法可以一次完成所有操作以提高效率?

java android multidimensional-array android-bitmap

5
推荐指数
1
解决办法
1601
查看次数