【问题标题】:Crop Imageview using input Specific Length and width使用输入特定长度和宽度裁剪 Imageview
【发布时间】:2013-10-04 14:31:06
【问题描述】:

我有应用程序。我想裁剪图像视图中显示的图片。我想要具有特定长度和宽度的作物。你能帮助我吗?我有代码,但是该代码直接从图库中裁剪出来。

我只想裁剪具有特定长度和宽度的图像视图。其中长度和宽度只需用户手动输入。

【问题讨论】:

  • 不....我不做中心裁剪。我想要用户手动输入的长度和宽度。就像在 Java 上使用输入框进行输入一样。这行得通吗?

标签: android imageview crop


【解决方案1】:

如果您不介意将新库添加到项目中只是为了为您加载图像,您可以轻松添加 Glide 以裁剪本地可绘制对象或来自网络的图像。

在您的 build.gradle(模块应用程序)中

compile 'com.github.bumptech.glide:glide:3.6.0'

您可以使用以下内容裁剪图像:

 final ImageView myImage = (ImageView) findViewById(R.id.myimageview);

        final int myWidth = 210;
        final int myHeight = 80;
        Glide.with(getApplicationContext())
                .load(R.drawable.example_drawable) // you can add any drawable or url of an image here
                .asBitmap()
                .into(new SimpleTarget<Bitmap>(myWidth, myHeight) {
                    @Override
                    public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
                        // Do something with bitmap here.
                        Bitmap bm = Bitmap.createBitmap(bitmap, 0, 0, myWidth, myHeight);
                        myImage.setImageBitmap(bm);
                    }
                });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多