0
MonoTouch를 처음 사용하고 있으며 표준 C# 코드를 MonoTouch 호환 코드로 변환하여 최근에 iPhone 응용 프로그램 내에서 사용할 수있게되었습니다.MonoTouch의 CGBitmapContext가 잘못된 핸들 예외를 던졌습니다
System.Exception: Invalid handle
at MonoTouch.CoreGraphics.CGContext..ctor (IntPtr handle, Boolean owns) [0x00022] in /Developer/MonoTouch/Source/monotouch/src/shared/CoreGraphics/CGContext.cs:136
at MonoTouch.CoreGraphics.CGBitmapContext..ctor (IntPtr data, Int32 width, Int32 height, Int32 bitsPerComponent, Int32 bytesPerRow, MonoTouch.CoreGraphics.CGColorSpace colorSpace, CGImageAlphaInfo bitmapInfo) [0x00000] in <filename unknown>:0
at Jargoon.Data.Arcs.Loader.ExtractWriteableBitmap (Jargoon.Data.Arcs.Records.RGBPaletteRecord rgbPalette, Double dpi, Jargoon.Data.Arcs.Raschts.ChartIndexFile indexFile, Jargoon.Data.Arcs.Raschts.RasterChartFile chartFile) [0x00079] in /Users/jacknutkins/Desktop/Jargoon/ARCSViewer/ARCSViewer/Loader.cs:569
at Jargoon.Data.Arcs.Loader.GetHiResImage (Jargoon.Data.Arcs.Records.RGBPaletteRecord rgbPalette) [0x00000] in /Users/jacknutkins/Desktop/Jargoon/ARCSViewer/ARCSViewer/Loader.cs:361
at ARCSViewer.ARCSViewerViewController.ViewDidLoad() [0x0001c] in /Users/jacknutkins/Desktop/Jargoon/ARCSViewer/ARCSViewer/ARCSViewerViewController.cs:37
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29
at ARCSViewer.Application.Main (System.String[] args) [0x00000] in /Users/jacknutkins/Desktop/Jargoon/ARCSViewer/ARCSViewer/Main.cs:17
: 여기
private CGBitmapContext ExtractWriteableBitmap(RGBPaletteRecord rgbPalette, double dpi, ChartIndexFile indexFile, RasterChartFile chartFile)
{
CGBitmapContext bitmapImage = null;
TileRecord tile;
// calc the number of tiles in each plane
int tileCountX = indexFile.TileIndexRecords.Max(ti => ti.X);
int tileCountY = indexFile.TileIndexRecords.Max(ti => ti.Y);
// create the big picture
int pixelWidth = (tileCountX + 1) * TileRecord.PixelWidth;
int pixelHeight = (tileCountY + 1) * TileRecord.PixelHight;
int intDPI = Convert.ToInt32(dpi);
int bytesPerRow = (int)TileRecord.PixelWidth * 4; // note that bytes per row should
//be based on width, not height.
CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
CGImageAlphaInfo info = CGImageAlphaInfo.NoneSkipFirst;
// create the big picture
bitmapImage = new CGBitmapContext(System.IntPtr.Zero, pixelWidth, pixelHeight, intDPI, intDPI, colorSpace, info);
byte[] sourceArray;
RectangleF sourceRect;
//copy the tiles into the big picture
int index = 0;
foreach (TileIndexRecord tileIndexRecord in indexFile.TileIndexRecords)
{
// get the tile record
tile = chartFile.TileRecords[index];
// extract the byte array for the given palette
sourceArray = tile.GetBytes(rgbPalette);
GCHandle pinnedArray = GCHandle.Alloc(sourceArray, GCHandleType.Pinned);
IntPtr pointer = pinnedArray.AddrOfPinnedObject();
//do your stuff
//pinnedArray.Free();
CGImage image = new CGImage(pointer);
sourceRect = new RectangleF(0, 0, TileRecord.PixelWidth, TileRecord.PixelHight);
bitmapImage.DrawImage(new RectangleF(0,0,128,128),image);
// copy the tile image into the big picture
//bitmapImage.WritePixels(sourceRect, sourceArray, TileRecord.Stride, (tileIndexRecord.X * TileRecord.PixelWidth), (tileIndexRecord.Y * TileRecord.PixelHight));
// increment the index
index++;
}
return bitmapImage;
}
스택 추적입니다 : 그러나 나는 내가 비트 맵 컨텍스트를 반환하는 데 사용하는이 방법에 문제로 실행 한 코드를 변환하는 데 성공했습니다 세드릭 MonoTouch 그렇게 시도하고 부담 나와 함께 그 눈부시게 분명하지만 만약 누군가가 설명 할 수에 내가 아주 새로운 해요
// create the big picture
bitmapImage = new CGBitmapContext(System.IntPtr.Zero, pixelWidth, pixelHeight, intDPI, intDPI, colorSpace, info);
: 오류가 줄에서 발생?
건배에 대한 건배, 내가 가진 스택 추적의 나머지 부분과 함께 질문을 편집했습니다. 컨텍스트를 해제하는 방법에 대해 어떻게 생각합니까? 건배 –
이 코드를 처음 호출하거나 몇 차례 반복 한 후에 예외가 발생합니까? 그리고 어떤 인수를 CGBitmapContext 생성자에 전달합니까? (예를 들어 너무 큰 비트 맵을 만들려고하면 실패 할 것입니다)? –
예 (그게 너무 컸습니다) 문제였습니다. 어젯밤에 알아 냈습니다. 고마워요. –