Перейти к содержанию
Fire Monkey от А до Я

tromani

Пользователи
  • Постов

    31
  • Зарегистрирован

  • Посещение

Активность репутации

  1. Like
    tromani получил реакцию от AngryOwl в Ошибка "Bitmap size too big"   
    в общем вышел из положения, очередным костылем к FMX, если кому понадобиться вот полный текст, работает сносно
    procedure JBLoadFromFile(FileName:string; const ABitmap : TBitmap;W,H:integer); procedure SwapRB(var src:TJavaArray<Integer>); var i:integer; begin for i:= 0 to src.Length-1 do src.Items[i]:=(src.Items[i] and $FF00FF00) or ((src.Items[i] and $000000FF) shl 16) or ((src.Items[i] and $00FF0000) shr 16); end; procedure JBitmapToBitmap(const AImage: JBitmap; const ResBitmap: TBitmap); var ImageData: TJavaArray<Integer>; BitmapData: TBitmapData; Width, Height: Integer; begin Width := AImage.getWidth; Height := AImage.getHeight; try ResBitmap.SetSize(Width,Height); ImageData := TJavaArray<Integer>.Create(Width * Height); AImage.getPixels(ImageData, 0, Width, 0, 0, Width, Height); SwapRB(ImageData); if ResBitmap.Map(TMapAccess.maWrite, BitmapData) then try Move(ImageData.Data^, BitmapData.Data^, Width * Height * SizeOf(Integer)); finally ResBitmap.Unmap(BitmapData); end else ResBitmap.Clear(TAlphaColorRec.Green); except ResBitmap.Clear(TAlphaColorRec.Green); end; end; function calculateInSampleSize(options:JBitmapFactory_Options; reqWidth, reqHeight:integer):integer; var nh,nw:integer; heightRatio,widthRatio:integer; begin nh:=options.outHeight; nw:=options.outWidth; result:=1; if (nh> reqHeight) or (nw > reqWidth) then begin heightRatio:=round( nh / reqHeight); widthRatio:= round(nw /reqWidth); if heightRatio<widthRatio then Result:=heightRatio else Result:=widthRatio; end; end; var bmf_options:JBitmapFactory_Options; cbm:JBitmap; begin bmf_options:=TJBitmapFactory_Options.JavaClass.init; bmf_options.inJustDecodeBounds := true; TJBitmapFactory.JavaClass.decodeFile(StringToJString(FileName),bmf_options); bmf_options.inSampleSize := calculateInSampleSize(bmf_options, W, H); bmf_options.inJustDecodeBounds := false; try cbm:=TJBitmapFactory.JavaClass.decodeFile(StringToJString( FileName),bmf_options); except cbm:=nil; end; if Assigned(cbm) then try JBitmapToBitmap(cbm,ABitmap) except ABitmap.Clear(TAlphaColorRec.Blue); end else ABitmap.Clear(TAlphaColorRec.Green); end; может кто улучшит, подскажет чтото новое
     
  2. Like
    tromani получил реакцию от Евгений Корепов в Ошибка "Bitmap size too big"   
    попробуем продолжить, на стареньком но не очень уж мертвом устройстве загрузка файла происходит катострофически невероятно долго. нашел более менее нормальный по скорости способ. но и тут не так все хорошо может ктото поймет в чем дело:
    procedure JBitmapToBitmap(const AImage: JBitmap; const ResBitmap: TBitmap); var ImageData: TJavaArray<Integer>; BitmapData: TBitmapData; Width, Height: Integer; begin Width := AImage.getWidth; Height := AImage.getHeight; try ImageData := TJavaArray<Integer>.Create(Width * Height); ResBitmap.SetSize(Width,Height); AImage.getPixels(ImageData, 0, Width, 0, 0, Width, Height); if ResBitmap.Map(TMapAccess.maWrite, BitmapData) then try Move(ImageData.Data^, BitmapData.Data^, Width * Height * SizeOf(Integer)); finally ResBitmap.Unmap(BitmapData); end else ResBitmap.Clear(TAlphaColorRec.Green); except ResBitmap.Clear(TAlphaColorRec.Green); end; end; function calculateInSampleSize(options:JBitmapFactory_Options; reqWidth, reqHeight:integer):integer; var nh,nw:integer; heightRatio,widthRatio:integer; begin nh:=options.outHeight; nw:=options.outWidth; result:=1; if (nh> reqHeight) or (nw > reqWidth) then begin heightRatio:=round( nh / reqHeight); widthRatio:= round(nw /reqWidth); if heightRatio<widthRatio then Result:=heightRatio else Result:=widthRatio; end; end; var cur_bitmap:JBitmap; bitmap_option:JBitmapFactory_Options; cf_path:string; begin bitmap_option:=TJBitmapFactory_Options.JavaClass.init; bitmap_option.inJustDecodeBounds := true; TJBitmapFactory.JavaClass.decodeFile(StringToJString(cf_path),bitmap_option); bitmap_option.inSampleSize := calculateInSampleSize(bitmap_option, Round(Image5.Width), Round(Image5.Height)); bitmap_option.inJustDecodeBounds := false; try cur_bitmap:=TJBitmapFactory.JavaClass.decodeFile(StringToJString(cf_path),bitmap_option); except cur_bitmap:=nil; end; if Assigned(cur_bitmap) then JBitmapToBitmap(cur_bitmap,Image5.Bitmap); end; таким образом все просто шикарно, загрузка мгновенно все норм кроме одного, вместо синего - красный, не знаю как решить
  3. Like
    tromani получил реакцию от dnekrasov в Ошибка "Bitmap size too big"   
    в общем итоговая процедура получилась у меня вот так, при этом заработало там где до этого не работало
    procedure CheckAndLoadFromStream(FileName:string; const ABitmap : TBitmap); var MaxImageSize : Integer; ABitmapSurface,ABitmapSurfaceResize : TBitmapSurface; mxH,mxW:integer; begin ABitmapSurface:=TBitmapSurface.Create; ABitmapSurfaceResize:=TBitmapSurface.Create; TBitmapCodecManager.LoadFromFile(FileName,ABitmapSurface); MaxImageSize:=TCanvasManager.DefaultCanvas.GetAttribute(TCanvasAttribute.MaxBitmapSize); if (ABitmapSurface.Height>MaxImageSize) or (ABitmapSurface.Width>MaxImageSize) then begin if ABitmapSurface.Height>ABitmapSurface.Width then begin mxH:=MaxImageSize; mxW:=Round(mxH/ABitmapSurface.Height*ABitmapSurface.Height); end else begin mxW:=MaxImageSize; mxH:=Round(mxW/ABitmapSurface.Width*ABitmapSurface.Height); end; end else begin mxW:=ABitmapSurface.Width; mxH:=ABitmapSurface.Height; end; ABitmapSurfaceResize.SetSize(mxW,mxH); ABitmapSurfaceResize.StretchFrom(ABitmapSurface,mxW,mxH); FreeAndNil(ABitmapSurface); ABitmap.SetSize(mxW,mxH); ABitmap.Assign(ABitmapSurfaceResize); FreeAndNil(ABitmapSurfaceResize); end;
  4. Like
    tromani получил реакцию от dnekrasov в Ошибка "Bitmap size too big"   
    попробуй переставь
    ABitmapSurfaceResize:=TBitmapSurface.Create; после 
    ABitmapSurface:=TBitmapSurface.Create; и
    после определения максимальных длины и ширины  - сделай ABitmapSurfaceResize.SetSize
    у меня по крайней мере заработало.
     
  5. Like
    tromani получил реакцию от Rusland в Ошибка "Bitmap size too big"   
    в общем итоговая процедура получилась у меня вот так, при этом заработало там где до этого не работало
    procedure CheckAndLoadFromStream(FileName:string; const ABitmap : TBitmap); var MaxImageSize : Integer; ABitmapSurface,ABitmapSurfaceResize : TBitmapSurface; mxH,mxW:integer; begin ABitmapSurface:=TBitmapSurface.Create; ABitmapSurfaceResize:=TBitmapSurface.Create; TBitmapCodecManager.LoadFromFile(FileName,ABitmapSurface); MaxImageSize:=TCanvasManager.DefaultCanvas.GetAttribute(TCanvasAttribute.MaxBitmapSize); if (ABitmapSurface.Height>MaxImageSize) or (ABitmapSurface.Width>MaxImageSize) then begin if ABitmapSurface.Height>ABitmapSurface.Width then begin mxH:=MaxImageSize; mxW:=Round(mxH/ABitmapSurface.Height*ABitmapSurface.Height); end else begin mxW:=MaxImageSize; mxH:=Round(mxW/ABitmapSurface.Width*ABitmapSurface.Height); end; end else begin mxW:=ABitmapSurface.Width; mxH:=ABitmapSurface.Height; end; ABitmapSurfaceResize.SetSize(mxW,mxH); ABitmapSurfaceResize.StretchFrom(ABitmapSurface,mxW,mxH); FreeAndNil(ABitmapSurface); ABitmap.SetSize(mxW,mxH); ABitmap.Assign(ABitmapSurfaceResize); FreeAndNil(ABitmapSurfaceResize); end;
×
×
  • Создать...