调整位图裁剪,而不是在视图缩放

编程入门 行业动态 更新时间:2024-10-27 13:20:52
本文介绍了调整位图裁剪,而不是在视图缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我无法弄清楚如何调整位图。基于此职位Bitmap.createScaledBitmap是要做到这一点,但它只是不为我工作。因为我在的onDraw尽一切观点的性质,所以我不认为我可以用一个布局或ImageView的。下面是我在做什么:

I can't figure out how to resize a bitmap. Based on posts here Bitmap.createScaledBitmap is the way to do it but it just doesn't work for me. Because of the nature of the view I'm doing everything in onDraw so I don't think I can use a layout or ImageView. Here's what I'm doing:

我有帝国大厦这是200x200的的图像。我运行这个code来进行设置:

I have an image of the Empire State Building that's 200x200. I run this code to set it up:

private void setupBitmap() { int bitmapSize = 100; Bitmap originalBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.empirestate_sm); myBitmap = Bitmap.createScaledBitmap(originalBitmap, bitmapSize, bitmapSize, true); }

这是我的onDraw:

This is is my onDraw:

protected void onDraw(Canvas canvas) { canvas.drawBitmap(myBitmap, 0, 0, null); }

这是结果,注意形象只是裁剪,而不是调整:

And here is the result, note the image is just cropped and not resized:

只是为了S&放大器; G的,如果我设置bitmapSize = 200它看起来是这样的:

Just for s&g's if I set the bitmapSize = 200 it looks like this:

推荐答案

好,我理解了它。什么工作对我来说是离开位图是当你创建它。然后,当你画在画布上把它设置为合适的尺寸。我假设createScaledBitmap功能坏了?

Ok I've figured it out. What worked for me is leaving the bitmap as is when you create it. Then when you draw it on the canvas set it to the right size. I'm assuming the createScaledBitmap function is broken??

myCanvas.drawBitmap (landmarkImg, null, new RectF((float)0,(float)0,newWidth,newHeight),null);

更多推荐

调整位图裁剪,而不是在视图缩放

本文发布于:2023-08-02 03:48:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1274368.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:是在   位图   而不   缩放   视图

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!