首页 \ 问答 \ 如何使用Canvas在图片周围旋转图片?(How would one rotate an image around itself using Canvas?)

如何使用Canvas在图片周围旋转图片?(How would one rotate an image around itself using Canvas?)

我无法使用Canvas在图片周围旋转图片。

既然你不能旋转图像,你必须旋转画布:如果我旋转画布的程度,我想旋转的原点改变。 我不知道如何跟踪这个变化。

这是我现在的代码: http : //pastie.org/669023

演示在http://preview.netlashproject.be/cog/

如果你想给一些东西一个镜头,压缩的代码和图像位于http://preview.netlashproject.be/cog/cog.zip


I'm having trouble roating an image around itself using Canvas.

Since you can't rotate an image you have to rotate the canvas: if I rotate the canvas by a degree the origin around which I want to rotate changes. I don't get how to track this change.

This is my current code: http://pastie.org/669023

And a demo is at http://preview.netlashproject.be/cog/

If you want to give things a shot the zipped up code and image is at http://preview.netlashproject.be/cog/cog.zip


原文:https://stackoverflow.com/questions/1621321
更新时间:2022-06-02 19:06

最满意答案

基本上,您希望打开与RTSP服务器主机名/端口的普通客户端套接字连接,然后发布RTSP OPTIONS请求。 如果服务器以“RTSP / 1.0 200 OK”响应,则表示流服务已启动,否则将关闭。

我写了一个快速而脏的样本RTSP检查并进行了测试。 随意根据您的需求进行调整:

更新处理UI操作在您的活动类中,创建以下字段:

private static final int MESSAGE_RTSP_OK = 1;
private static final int MESSAGE_RTSP_ERROR = -1;

private Handler handler;

在你的onCreate方法中,添加:

    handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case MESSAGE_RTSP_OK:
                    //show_player(); 
                    // implement ui operation here
                    break;
                case MESSAGE_RTSP_ERROR:
                    //show_error();
                    break;
            }
        }
    };

然后运行此示例代码: 更新了rtsp检查代码

    new Thread() {
        public void run() {
            try {
                Socket client = new Socket("a1352.l1857053128.c18570.g.lq.akamaistream.net", 554);
                OutputStream os = client.getOutputStream();
                os.write("OPTIONS * RTSP/1.0\n".getBytes());
                os.write("CSeq: 1\n\n".getBytes());
                os.flush();

                //NOTE: it's very important to end any rtsp request with \n\n (two new lines). The server will acknowledge that the request ends there and it's time to send the response back.

                BufferedReader br =
                        new BufferedReader(
                                new InputStreamReader(
                                        new BufferedInputStream(client.getInputStream())));

                StringBuilder sb = new StringBuilder();
                String responseLine = null;

                while (null != (responseLine = br.readLine()))
                    sb.append(responseLine);
                String rtspResponse = sb.toString();
                if(rtspResponse.startsWith("RTSP/1.0 200 OK")){
                    // RTSP SERVER IS UP!!
                     handler.obtainMessage(MESSAGE_RTSP_OK).sendToTarget();
                } else {
                    // SOMETHING'S WRONG

                    handler.obtainMessage(MESSAGE_RTSP_ERROR).sendToTarget();
                }
                Log.d("RTSP reply" , rtspResponse);
                client.close();
            } catch (IOException e) {
                // NETWORK ERROR such as Timeout 
                e.printStackTrace();

                handler.obtainMessage(MESSAGE_RTSP_ERROR).sendToTarget();
            }

        }
    }.start();`

在这个测试中,我选择了公共NASA TV rtsp服务器: rtsp://a1352.l1857053128.c18570.g.lq.akamaistream.net:554

代码发送以下rtsp请求:

OPTIONS * RTSP/1.0 CSeq: 1

并收到以下回复:

RTSP/1.0 200 OK Server: QTSS-Akamai/6.0.3 (Build/526.3; Platform/Linux; Release/Darwin; ) Cseq: 1 Public: DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, OPTIONS, ANNOUNCE, RECORD

如果您正在寻找更复杂的检查,请随时深入了解rtsp协议文档并根据您自己的需要增强代码: https//www.ietf.org/rfc/rfc2326.txt

如果需要更多信息,请告诉我。


Basically you want to open a plain client socket connection to the RTSP server hostname/port and then post a RTSP OPTIONS request. If the server responds with a "RTSP/1.0 200 OK", it means the streaming service is up, otherwise it's down.

I wrote a quick and dirty sample RTSP check and tested it out. Feel free to adapt it to your needs:

Update handling UI operations In your activity class, create these fields:

private static final int MESSAGE_RTSP_OK = 1;
private static final int MESSAGE_RTSP_ERROR = -1;

private Handler handler;

in your onCreate method, add:

    handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case MESSAGE_RTSP_OK:
                    //show_player(); 
                    // implement ui operation here
                    break;
                case MESSAGE_RTSP_ERROR:
                    //show_error();
                    break;
            }
        }
    };

Then run this sample code: Updated rtsp check code

    new Thread() {
        public void run() {
            try {
                Socket client = new Socket("a1352.l1857053128.c18570.g.lq.akamaistream.net", 554);
                OutputStream os = client.getOutputStream();
                os.write("OPTIONS * RTSP/1.0\n".getBytes());
                os.write("CSeq: 1\n\n".getBytes());
                os.flush();

                //NOTE: it's very important to end any rtsp request with \n\n (two new lines). The server will acknowledge that the request ends there and it's time to send the response back.

                BufferedReader br =
                        new BufferedReader(
                                new InputStreamReader(
                                        new BufferedInputStream(client.getInputStream())));

                StringBuilder sb = new StringBuilder();
                String responseLine = null;

                while (null != (responseLine = br.readLine()))
                    sb.append(responseLine);
                String rtspResponse = sb.toString();
                if(rtspResponse.startsWith("RTSP/1.0 200 OK")){
                    // RTSP SERVER IS UP!!
                     handler.obtainMessage(MESSAGE_RTSP_OK).sendToTarget();
                } else {
                    // SOMETHING'S WRONG

                    handler.obtainMessage(MESSAGE_RTSP_ERROR).sendToTarget();
                }
                Log.d("RTSP reply" , rtspResponse);
                client.close();
            } catch (IOException e) {
                // NETWORK ERROR such as Timeout 
                e.printStackTrace();

                handler.obtainMessage(MESSAGE_RTSP_ERROR).sendToTarget();
            }

        }
    }.start();`

For this test I picked the public NASA TV rtsp server: rtsp://a1352.l1857053128.c18570.g.lq.akamaistream.net:554

The code sends the following rtsp request:

OPTIONS * RTSP/1.0 CSeq: 1

And receives the following response:

RTSP/1.0 200 OK Server: QTSS-Akamai/6.0.3 (Build/526.3; Platform/Linux; Release/Darwin; ) Cseq: 1 Public: DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, OPTIONS, ANNOUNCE, RECORD

If you are looking for more complex checks, feel free to dive into the rtsp protocol documentation and enhance the code per your own needs: https://www.ietf.org/rfc/rfc2326.txt

Please let me know if more information is needed.

相关问答

更多
  • 由Praful解决,在Manifest.xml中添加Internet权限 AndroidManifest.xml中
    以下适用于我: 代码= FlsBObg-1BQ在你的情况。 你会得到很多的网址,我选择返回最好的质量。 private String getRstpLinks(String code){ String[] urls = new String[3]; String link = "http://gdata.youtube.com/feeds/api/videos/" + code + "?alt=json"; String json = getJsonString(link); // ...
  • 这里有一个类似的问题: 在Android应用程序中播放RTSP流媒体 您可能还需要在Android开发者页面查看支持的媒体格式: http : //developer.android.com/guide/appendix/media-formats.html 没有任何代码我不确定你到底是什么。 希望这可以帮助。 There is a similar question to yours here: Play RTSP streaming in an Android application You might ...
  • 使用MJPEG流而不是RTSP。 经过大量研究,我发现了一个MJPEG查看器类,可以实时播放实时流(取决于您的网络连接)。 这是代码Android和MJPEG Use MJPEG stream, instead of RTSP. After lots of research, I´ve found an MJPEG viewer class that plays live stream near in real time (depending on your network connection). Her ...
  • 格式为rtsp://[username[:password]@]ip_address[:rtsp_port]/server_URL[?param1=val1[¶m2=val2]...[¶mN=valN]] 发送用户名和密码的另一种方法: Uri source = Uri.parse("rtsp://iphere:554/cam/realmonitor"); Map headers = new HashMap(); headers ...
  • 基本上,您希望打开与RTSP服务器主机名/端口的普通客户端套接字连接,然后发布RTSP OPTIONS请求。 如果服务器以“RTSP / 1.0 200 OK”响应,则表示流服务已启动,否则将关闭。 我写了一个快速而脏的样本RTSP检查并进行了测试。 随意根据您的需求进行调整: 更新处理UI操作在您的活动类中,创建以下字段: private static final int MESSAGE_RTSP_OK = 1; private static final int MESSAGE_RTSP_ERROR = ...
  • 您可以通过Vitamio Libary轻松完成。 Vitamio支持Android和iOS中的720p / 1080p高清,mp4,mkv,m4v,mov,flv,avi,rmvb,rm,ts,tp等多种视频格式。 Vitamio几乎支持所有流行的流媒体协议,包括HLS(m3u8),MMS,RTSP,RTMP和HTTP。 你可以从这里下载演示。 You can easily do it via Vitamio Libary. Vitamio supports 720p/1080p HD, mp4, mkv, ...
  • 你应该为intent参数调用getData() ,或者在获取URI之前执行setIntent(intent) 。 onNewIntent()不会自动设置新的意图。 更新:所以,这里有两种方法可以实现onNewIntent() 。 第一个用旧的意图替换旧的意图,所以当你稍后调用getIntent() ,你会收到新的意图。 @Override protected void onNewIntent(final Intent intent) { super.onNewIntent(intent); ...
  • 很难确定没有更多信息和查看代码,但最可能的问题是您的提供商阻止其网络上的这种类型的连接 - 一些运营商将阻止'上行'流媒体流量,要么保留带宽,要么因为它们可能认为这是一种类似VoIP的服务,与其中一项服务竞争。 它在WiFi上工作的原因是,你的Android设备和你的相机很可能都在同一个网络上,它们之间没有防火墙等。 Its hard to be sure without more info and seeing the code, but the most likely problem is that y ...
  • 回旋处的建议 - 使用刚刚在android上编译的VLC将rtsp流下载到本地filesink。 下载完成后,只需使用本地文件的正常Intent字段值和mp4的mimetype播放该文件。 下面的剪辑应该播放下载的内容。 new Intent(Intent.ACTION_VIEW).setDataAndType(Uri.parse("file:///mnt/sdcard/myfile.mp4"), "video/mp4"); Android链接上的VLC: http : //forum.xda-deve ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)