我将我的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);
答案 0 :(得分:3)
相当于使用Quartz 2D和
UIGraphicsBeginImageContextWithOptions();
CGContextRef context = UIGraphicsGetCurrentContext(); //get the context we just made above
然后您可以将上下文导出为UIImage。