我試圖從蘋果示例代碼中保存圖形作爲從GLPaint
應用程序的圖像。
保存圖像在iPad(非視網膜)中工作正常,但它在iPad(視網膜)上運行時發出。
每當我在iPad視網膜上運行我的應用程序時,圖像大小是原來的1/4。
任何人都可以幫我解決這個問題嗎?保存圖像從GLPaint繪圖到iPad鼠標
0
A
回答
0
如果您使用的是glReadPixels
,那麼您的參數插入寬度和高度似乎有誤。您需要獲取GL緩衝區的寬度和高度,並將其插入glReadPixels
而不是幀寬和高度。對於視網膜而言,這些將是框架尺寸的兩倍。
從例子中提到的那些是backingWidth
和backingHeight
,你應該能夠隨時隨地得到他們使用:
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight);
因此,使用glReadPixels(0, 0, backingWidth, backingHeight, ...)
,並確保你讀入緩衝區也夠大。對於RGBA,這將是backingWidth*backingHeight*4
字節。
0
其他我見過泄漏記憶的方法,這裏是我發現和修改的一個剪輯,用於從GLPaint中捕捉圖像。
-(BOOL)iPhoneRetina{
return ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] && ([UIScreen mainScreen].scale == 2.0))?YES:NO;
}
void releasePixels(void *info, const void *data, size_t size) {
free((void*)data);
}
-(UIImage *) glToUIImage{
int imageWidth, imageHeight;
int scale = [self iPhoneRetina]?2:1;
imageWidth = self.frame.size.width*scale;
imageHeight = self.frame.size.height*scale;
NSInteger myDataLength = imageWidth * imageHeight * 4;
// allocate array and read pixels into it.
GLubyte *buffer = (GLubyte *) malloc(myDataLength);
glReadPixels(0, 0, imageWidth, imageHeight, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
// make data provider with data.
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer, myDataLength, releasePixels);
// prep the ingredients
int bitsPerComponent = 8;
int bitsPerPixel = 32;
int bytesPerRow = 4 * imageWidth;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGImageAlphaPremultipliedLast;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
// make the cgimage
CGImageRef imageRef = CGImageCreate(imageWidth, imageHeight, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
UIImage *myImage = [UIImage imageWithCGImage:imageRef scale:scale orientation:UIImageOrientationDownMirrored]; //Render image flipped, since OpenGL's data is mirrored
CGImageRelease(imageRef);
CGColorSpaceRelease(colorSpaceRef);
CGDataProviderRelease(provider);
return myImage;
}
相關問題
- 1. GLPaint - 將圖像保存爲矢量圖像
- 2. GLPaint保存功能(保存當前屏幕與背景圖像)
- 3. 保存imageRef從GLPaint創建完全黑色的圖像
- 4. 繪製並保存圖像
- 5. 從座標保存地圖圖像
- 6. 用鼠標繪圖
- 7. HTML畫布用鼠標單擊繪製圖像,保存座標但不提交
- 8. 鼠標,繪畫和滑塊圖像
- 9. 圖像拖動鼠標不被繪製
- 10. 在圖像上繪製鼠標點擊
- 11. Matlab:保存繪圖圖像,覆蓋plot.m
- 12. Java圖像點到鼠標
- 13. 爲ipad繪製大圖像
- 14. 保存可下繪圖到存儲器中的圖像
- 15. iPad繪圖:將圖像繪製到CGContext中
- 16. 將繪圖保存到圖像上,然後在繪圖上繪製其他線條並再次保存。
- 17. 保存從圖片框中的圖像,圖像是由圖形對象繪製
- 18. 鼠標懸停圖像保持不變
- 19. 繪圖點鼠標點擊
- 20. 鼠標繪圖程序Java
- 21. 將圖像從位圖保存到jpeg而不保存文件
- 22. 從MATLAB中保存圖像的圖像
- 23. 從UIImagePickerController保存圖像抓取圖像?
- 24. 從圖像路徑保存圖像
- 25. 將圖像從保存箱加載到我的圖像視圖
- 26. 將圖像綁定到鼠標光標
- 27. Java Graphics2D鼠標圖案繪圖
- 28. iPad Safari將鼠標事件映射到圖像地圖中的觸摸事件
- 29. 將標籤合併到圖像上並保存爲新圖像?
- 30. 在PictureBox中保存繪製的圖像
Thnx @ Matic..it works fine .. – Jhanvi