Android的 - 平局位图 [英] Android - draw bitmap

查看:119
本文介绍了Android的 - 平局位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的测试Android应用程序有一个单一的活动,的LoadImage,有两种方法:与OpenCV的处理图像的onCreate方法,并显示在屏幕5秒钟的图像的显示方法。以下是我迄今为止的显示方法:

My test Android app has a single activity, LoadImage, with two methods: an onCreate method that processes images with OpenCV, and a Display method which displays the image on the screen for 5 seconds. Here is what I have so far for the Display method:

[convert OpenCV matrix to a bitmap using an OpenCV method]

Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(bitmap, 0, 0, null);

try {
    synchronized (this) {
        wait(5000);
    }
} catch (InterruptedException e) {
}

和这里是单活动的XML文件(这是一个空白屏幕):

and here is the XML file for the single activity (it's a blank screen):

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</RelativeLayout>

如果我运行code原样,我得到......一个空白屏幕。我如何获得的位图显示?

If I run the code as-is, I get... a blank screen. How do I get the bitmaps to show up?

太感谢了。

推荐答案

试试这个:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"/>
</RelativeLayout>

和做在你的java code:

And do this in your java code:

onCreate()
{
    ImageView imageView = (ImageView) findViewById(R.id.imageView1);
}

您要发送的位图到画布上吧?

因此​​,在你的方法,你绘制成位图做到这一点那里。

So do this there in your method where you are drawing into the bitmap.

imageView.setImageBitmap(bitmap);

您不能直接设置画布到imageView1。

You can not set the canvas directly to the imageView1.

由于你在现实生活中知道,画布只是一个刷。在这里以同样的方式也画布只是一个刷。所以不要担心it.your编辑图像现在存储在位图而已。所以,这就是为什么的您可以直接设置位图由帆布editng后

Because as you know in real life, the canvas is just a brush. In the same way here also the canvas is only a brush. so dont worry about it.your edited image is now stored in the bitmap only. So thats why you can directly set the bitmap after editng by canvas.

这篇关于Android的 - 平局位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆