jfi*_*isk 5 android interface-builder ios ios5
将我的 OGLES 应用程序从 Android 移植到 iOS,并动态制作图像以绑定为纹理,如下所示:
Bitmap overlayBitmap = Bitmap.createBitmap(512,512, Bitmap.Config.ARGB_4444);
// get a canvas to paint over the bitmap
Canvas canvas = new Canvas(overlayBitmap);
overlayBitmap.eraseColor(0);
// Draw the text
TextPaint textPaint = new TextPaint();
textPaint.setTextSize(30);
textPaint.setAntiAlias(true);
textPaint.setARGB(0xff, 0x00, 0x00, 0x00);
textPaint.setTypeface(Typeface.DEFAULT_BOLD);
textPaint.measureText(stopName);
// get a background image from resources
// note the image format must match the bitmap format
cap.setBounds(0,0,8,49);
cap.draw(canvas);
overlayBackground.setBounds(8,0, (int) textPaint.measureText(stopName)+8, 49);
overlayBackground.draw(canvas); // draw the background to our bitmap
Rect overlayBounds=overlayBackground.getBounds();
spike.setBounds((((overlayBounds.right+8)/2)-((21/2))),48,(((overlayBounds.right+8)/2)+((21/2))),69);
spike.draw(canvas);
capR.setBounds(overlayBounds.right,0,overlayBounds.right+8,49);
capR.draw(canvas);
// draw the text centered
canvas.drawText(stopName,8,33, textPaint);
Run Code Online (Sandbox Code Playgroud)
等效方法是使用 Quartz 2D 和
UIGraphicsBeginImageContextWithOptions();
CGContextRef context = UIGraphicsGetCurrentContext(); //get the context we just made above
Run Code Online (Sandbox Code Playgroud)
然后您可以将上下文导出为 UIImage。
| 归档时间: |
|
| 查看次数: |
2392 次 |
| 最近记录: |