图像在画布上为JPEG文件 [英] Image on canvas to JPEG file

查看:187
本文介绍了图像在画布上为JPEG文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在画布上绘制2D图像。

我要保存在画布上为JPEG文件中显示的图像,我该怎么办呢?

解决方案
  1. 创建一个空的位图
  2. 创建一个新的Canvas对象,这个位图传递给它
  3. 在调用view.draw(Canvas)的通过它您刚才创建的画布对象。 <一href="http://developer.android.com/intl/fr/reference/android/view/View.html#draw%28android.graphics.Canvas">Refer方法的详细资料。
  4. 使用Bitmap.com preSS()写的位图的内容到OutputStream,文件可能。

伪code:

 位图位= Bitmap.createBitmap(view.getWidth(),view.getHeight(),Bitmap.Config.ARGB_8888);
帆布油画=新的Canvas(位);
view.draw(画布);
bitmap.com preSS(Bitmap.Com pressFormat.JPEG,100,FOS);
 

I'm drawing 2D images on the canvas.

I want to save image shown on canvas to JPEG file, how can I do it?

解决方案

  1. create an empty bitmap
  2. create a new Canvas object and pass this bitmap to it
  3. call view.draw(Canvas) passing it the canvas object you just created. Refer Documentation of method for details.
  4. Use Bitmap.compress() to write the contents of the bitmap to an OutputStream, file maybe.

Pseudo code:

Bitmap  bitmap = Bitmap.createBitmap( view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas); 
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); 

这篇关于图像在画布上为JPEG文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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