I am using a Custom ImageView. In its onDraw I do some processing by using the canvas which is like drawing line, bitmaps based on user touch.
我正在使用自定义ImageView。在它的onDraw中,我使用画布进行一些处理,就像绘制线,基于用户触摸的位图。
To save the resultant snapshot when the user want to save the image, we are using drawingCache
要在用户想要保存图像时保存结果快照,我们使用drawingCache
imageView.setDrawingCacheEnabled(true;
Bitmap.createBitmap(imageView.getDrawingCache(), 0, 0,
imageView.getHeight(), imageView.getWidth(),
matrix, true).compress(CompressFormat.JPEG, 95,
new FileOutputStream(file));
Of course I can use this to get the actual image while user presses save but the image does not contain any of the processing done on the imageView.
当然,我可以使用它来获取实际图像,同时用户按下保存但图像不包含在imageView上完成的任何处理。
Bitmap bmp = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
Bitmap.createBitmap(bmp, 0, 0,
bmp.getWidth(), bmp.getHeight(),
matrix, true).compress(CompressFormat.JPEG, 95,
new FileOutputStream(file));
Problem: The size of the image saved is the size of the imageView which is fullscreen but depends on the device. For smaller screen size phones it goes down to 240 X 320.
问题:保存的图像大小是imageView的大小,它是全屏的,但取决于设备。对于较小屏幕尺寸的手机,它可降至240 X 320。
Question:
题:
a. Is it possible to get a decent size image irrespective of the device screen size?
一个。无论设备屏幕尺寸如何,都可以获得合适的尺寸图像吗?
b. Is it possible to do Image Processing directly on the Image that is being used in the Custom ImageView?
湾是否可以直接在Custom ImageView中使用的图像上进行图像处理?
Thanks in anticipation!
在期待中感谢!
Any thoughts?
有什么想法吗?
2 个解决方案
#1
0
Maybe an alternative would be use the Canvas class to do some of your drawing and image display: javadoc: android.graphics.Canvas.
也许替代方法是使用Canvas类来完成一些绘图和图像显示:javadoc:android.graphics.Canvas。
The ImageView class is not the best when images need to "refreshed" often.
当图像需要经常“刷新”时,ImageView类不是最好的。
If you decide to stick to ImageView, don't create the bitmap using the ImageView's dimensions. Retain the aspect ratio of the image, and compose your bitmap according to the big dimensions you need. The imageView will shrink it (if needed) to fit the screen.
如果您决定坚持使用ImageView,请不要使用ImageView的尺寸创建位图。保留图像的纵横比,并根据您需要的大尺寸构成位图。 imageView将缩小它(如果需要)以适合屏幕。
#2
0
You can use
您可以使用
Bitmap.createScaledBitmap(Bitmap b, int newWidth, int newHieght, boolean filter);
and to get a bitmap from resources use
并从资源使用中获取位图
Bitmap image = BitmapFactory.decodeResource(..)
you can then use
然后你可以使用
ImageView.setImageBitmap(Bitmap bm)
to set the new bitmap to the imageview
将新位图设置为imageview
#1
0
Maybe an alternative would be use the Canvas class to do some of your drawing and image display: javadoc: android.graphics.Canvas.
也许替代方法是使用Canvas类来完成一些绘图和图像显示:javadoc:android.graphics.Canvas。
The ImageView class is not the best when images need to "refreshed" often.
当图像需要经常“刷新”时,ImageView类不是最好的。
If you decide to stick to ImageView, don't create the bitmap using the ImageView's dimensions. Retain the aspect ratio of the image, and compose your bitmap according to the big dimensions you need. The imageView will shrink it (if needed) to fit the screen.
如果您决定坚持使用ImageView,请不要使用ImageView的尺寸创建位图。保留图像的纵横比,并根据您需要的大尺寸构成位图。 imageView将缩小它(如果需要)以适合屏幕。
#2
0
You can use
您可以使用
Bitmap.createScaledBitmap(Bitmap b, int newWidth, int newHieght, boolean filter);
and to get a bitmap from resources use
并从资源使用中获取位图
Bitmap image = BitmapFactory.decodeResource(..)
you can then use
然后你可以使用
ImageView.setImageBitmap(Bitmap bm)
to set the new bitmap to the imageview
将新位图设置为imageview