- 浏览: 46702 次
- 性别:
- 来自: 深圳
最新评论
//关键字:颜色合成,JPEG,PNG图片解压,Bitmap压缩。 package com.example.android.apis.graphics; import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.graphics.*; import android.os.Bundle; import android.view.KeyEvent; import android.view.*; import java.io.ByteArrayOutputStream; public class CreateBitmap extends GraphicsActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new SampleView(this)); } private static final int WIDTH = 50; private static final int HEIGHT = 50; private static final int STRIDE = 64; // must be >= WIDTH private static int[] createColors() { int[] colors = new int[STRIDE * HEIGHT]; for (int y = 0; y < HEIGHT; y++) { for (int x = 0; x < WIDTH; x++) { int r = x * 255 / (WIDTH - 1); int g = y * 255 / (HEIGHT - 1); int b = 255 - Math.min(r, g); int a = Math.max(r, g); colors[y * STRIDE + x] = (a << 24) | (r << 16) | (g << 8) | b;//颜色合成公式 } } return colors; } /* * 设alpha,red,green,blue都是0~255之间的数 * color32 = alpha << 24 | red << 16 | green << 8 | blue; * 色彩提取: * alpha = color32 >> 24; * red = color32 >> 16 & 0xFF; * green = color32 >> 8 & 0xFF; * blue = color32 & 0xFF; */ private static class SampleView extends View { private Bitmap[] mBitmaps; private Bitmap[] mJPEG; private Bitmap[] mPNG; private int[] mColors; private Paint mPaint; private static Bitmap codec(Bitmap src, Bitmap.CompressFormat format, int quality) { ByteArrayOutputStream os = new ByteArrayOutputStream(); src.compress(format, quality, os); //将Bitmap压缩成图片文件。 byte[] array = os.toByteArray(); return BitmapFactory.decodeByteArray(array, 0, array.length);//将byte数组解压为Bitmap; } /* * 如果返回true,可以通过传递一个相应的输出流到BitmapFactory.decodeStream()来重构该位图。 * 注意:并非所有的格式都直接支持位图结构, * format 图像的压缩格式; * quality 图像压缩比的值,0-100。 0 意味着小尺寸压缩,100意味着高质量压缩。对于有些格式,比如无损压缩的PNG,它就会忽视quality这个参数设置。 * stream 写入压缩数据的输出流 */ boolean compress(Bitmap.CompressFormat format, int quality, OutputStream stream) public SampleView(Context context) { super(context); setFocusable(true); mColors = createColors(); int[] colors = mColors; mBitmaps = new Bitmap[6]; // these three are initialized with colors[] mBitmaps[0] = Bitmap.createBitmap(colors, 0, STRIDE, WIDTH, HEIGHT, Bitmap.Config.ARGB_8888); mBitmaps[1] = Bitmap.createBitmap(colors, 0, STRIDE, WIDTH, HEIGHT, Bitmap.Config.RGB_565); mBitmaps[2] = Bitmap.createBitmap(colors, 0, STRIDE, WIDTH, HEIGHT, Bitmap.Config.ARGB_4444); //构造方法中直传COLORS数组。 // these three will have their colors set later mBitmaps[3] = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888); mBitmaps[4] = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.RGB_565); mBitmaps[5] = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_4444); for (int i = 3; i <= 5; i++) { mBitmaps[i].setPixels(colors, 0, STRIDE, 0, 0, WIDTH, HEIGHT); } //通过setPixels传入; mPaint = new Paint(); mPaint.setDither(true); // now encode/decode using JPEG and PNG mJPEG = new Bitmap[mBitmaps.length]; mPNG = new Bitmap[mBitmaps.length]; for (int i = 0; i < mBitmaps.length; i++) { mJPEG[i] = codec(mBitmaps[i], Bitmap.CompressFormat.JPEG, 80); mPNG[i] = codec(mBitmaps[i], Bitmap.CompressFormat.PNG, 0); } } @Override protected void onDraw(Canvas canvas) { canvas.drawColor(Color.WHITE); for (int i = 0; i < mBitmaps.length; i++) { canvas.drawBitmap(mBitmaps[i], 0, 0, null); canvas.drawBitmap(mJPEG[i], 80, 0, null); canvas.drawBitmap(mPNG[i], 160, 0, null); //将Bitmap压缩成JPEG和PNG,再解压成Bitmap 的显示效果不同。JPEG 只支持不透明像素 canvas.translate(0, mBitmaps[i].getHeight()); } // draw the color array directly, w/o craeting a bitmap object canvas.drawBitmap(mColors, 0, STRIDE, 0, 0, WIDTH, HEIGHT, true, null); canvas.translate(0, HEIGHT); canvas.drawBitmap(mColors, 0, STRIDE, 0, 0, WIDTH, HEIGHT, false, mPaint); } } }
发表评论
-
图片处理
2012-11-28 02:48 0http://www.linuxidc.com/Linux/2 ... -
Api Demo - .graphics(24)>>Cube
2012-08-03 15:18 1135package com.example.android.api ... -
Api Demo - .graphics(24)>>TouchRotateActivity
2012-08-03 15:07 1026package com.example.android.api ... -
Api Demo - .graphics(23)>>CubeMapActivity
2012-07-31 16:31 1375package com.opengl.test; imp ... -
opengles 学习关键字
2012-07-24 09:35 627主动渲染、平面着色、透视投影、near、索引法、glLight ... -
Api Demo - .graphics(21)>>StaticTriangleRenderer
2012-07-23 17:51 1227package com.example.android.api ... -
Api Demo - .graphics(20)>>CompressedTextureActivity
2012-07-23 16:50 1361/* * Copyright (C) 2008 The A ... -
Api Demo - .graphics(19)
2012-07-20 22:45 712package com.example.android.api ... -
Api Demo - .graphics(18)
2012-07-20 10:32 811package com.example.android.api ... -
Api Demo - .graphics(17)
2012-07-19 11:43 925/* package com.example.andro ... -
Api Demo - .graphics(16)
2012-07-18 14:54 596package com.example.android.api ... -
Api Demo - .graphics(15)
2012-07-18 12:55 791package com.example.android.api ... -
Api Demo - .graphics(14)
2012-07-18 11:50 798package com.example.android.api ... -
Api Demo - .graphics(13)
2012-07-17 11:38 892//关键字 Paint,MaskFilte,Path,Xfer ... -
Api Demo - .graphics(12)
2012-07-17 10:44 636<?xml version="1.0" ... -
Api Demo - .graphics(11)
2012-07-17 09:53 775//关键字:Shader ,ShapeDrawable pa ... -
Api Demo - .graphics(10)
2012-07-16 17:59 1034/* * Copyright (C) 2008 The A ... -
Api Demo - .graphics(8)
2012-07-16 10:43 645//关键字:ColorMatrixColorFilter; ... -
Api Demo - .graphics(7)
2012-07-16 09:53 720// 关键字:Porter-Duff package c ... -
Api Demo - .graphics(6)
2012-07-16 08:57 757//关键字:截取画布 p ...
相关推荐
Microsoft.Maui.Graphics是完全使用C#针对iOS,Android,Windows,macOS,Tizen和Linux的跨平台图形库。 使用此库,您可以使用通用API来定位多个抽象,从而使您可以在平台之间共享绘图代码,或在单个应用程序内混合...
代码很短,但是找jar包找的欲仙欲死,包括commons-io-1.4.jar,commons-logging-1.1.1.jar,docx4j-3.3.3.jar,freemarker.jar,google-collections.jar,log4j-1.2.8....xalan-2.7.0.jar,xmlgraphics-commons-1.3.jar
ArcGIS API for iOS 使您可使用 Objective C 构建多种应用程序(这些应用程序将运用 ArcGIS Server 提供的强大制图、地理编码、地理处理和自定义功能)并将它们部署到 Apple iPhone、iPod Touch 和 iPad 设备。API ...
WebGL Audio API for 3D Graphics in Three.JS by Igor Fortel 6 pages pdf short paper with a small demo
很多的官方demo,api,超值的啊。 animation ApiDemos.java ApiDemosApplication.java app appwidget content graphics media os text view
:示例代码介绍了如何使用API和遮挡剔除的可配置项。 :该示例代码提供了供离线超分辨率插件参考或使用的程序。 :该示例代码提供了可供参考或使用插件的程序。 有关更多信息,您可以在每个样本中检出README...
当前大多数搞机器人开发的用户所装的ROS是indigo版本,而且是基于Ubuntu14.04的。如果你跑别的版本的rbx代码老出错,不用怀疑,就是代码版本问题!ros by example for indigo volume 1很多地方(包括CSDN)都可以...
安卓开发例程,内置图形界面开发 硬件开发 nfc 媒体应用开发等官方demo
TDBProgress displays BDE operations progress for IDAPI drivers that support callback-functions. TDBIndexCombo is a visual interface component that provides your end- users with an easy means of ...
Tricks of the Windows video Game Programming <br>PART I Windows ....9 Designing Games ..................................................................................13 Types of Games ..........
围绕Unity新的实验性Vector API的简单包装,让您就像在HTML5画布中一样进行绘制。 演示基本的填充,笔触和填充规则。 例如: m_Graphics.MoveTo(900, 150);m_Graphics.BezierCurveTo(910, 250, 940, 250, 950, 250);...
android API demo 包括accessibility animation app content graphics media nfc os preference ...
API: MovieEvent()和draw()函数的调用速度不同。 因此,最好在MovieEvent()中进行所有帧处理。 或者,您可以首先保存所有帧,然后将它们作为图像文件顺序加载到draw()中。 删除背景的示例:chp16 / example...
Also see demo\tasks\localization. There are the required XML files. - if flag wpDontAddExternalFontLeading is active in property FormatOptionsEx the text will be formatted more like WPTools4/MS-...
in the demo directory. Installing JavaMail 1.2 To use the JavaMail 1.2 API, download the JavaMail 1.2 implementation, unbundle the javamail-1_2.zip file, and add the mail.jar file to your ...
这是一个自己整理的详细的英文Raphael 2.2参考文档,压缩包内包含pdf参考文档《Learning Raphael JS Vector Graphics》和示例demo。
RX Library 2.75 =============== The Set of Native Delphi Components for Borland Delphi versions 1, 2, 3, 4 & 5 and Borland C++ Builder 1, 3 & 4. ...5. A couple of simple demo applications.
- Added support for VGA graphics mode with 400 lines (partial fix for SF bug #2948724) - NE2K: Fixed "send buffer" command issue on big endian hosts - USB - converted common USB code plus devices ...
Much more reliable than using INIs<END><br>7 , Menubmp.zip This demonstrates how to add images to a menu.<END><br>8 , 3DBorders.zip This bas lets you create 3D Borders on your form.<END><br>9 ,...
14.2.9. StringToLower 14.2.10. StringToUpper 14.2.11. StringTrim 14.2.12. StripTags 14.3. 过滤器链 14.4. 编写过滤器 14.5. Zend_Filter_Input 14.5.1. Declaring Filter and Validator Rules 14.5.2....