John Scott Posted September 24, 2021 Share Posted September 24, 2021 I have a custom image format that I've had a Paint.NET plugin to view for about 4 years now. Unfortunately, with moving to Net5, it no longer compiles. Is there source for a sample plugin using the latest and greatest to load an image out there? Alternatively, given and int32[] of RGBA pixels, how would I convert that to a BitmapLayer (to add to a document)? I'm sorry to ask something so simple, but I'm having no luck with my google-fu Cheers John Quote Link to comment Share on other sites More sharing options...
toe_head2001 Posted September 24, 2021 Share Posted September 24, 2021 27 minutes ago, John Scott said: with moving to Net5, it no longer compiles. What's the error message? Can we see the source code? Quote (September 25th, 2023) Sorry about any broken images in my posts. I am aware of the issue. My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
John Scott Posted September 24, 2021 Author Share Posted September 24, 2021 DirectBitmap is in the StackOverflow link. Even older code is commented out. Thanks! private void AddLayer( Document mippedDocument, int8 mip, int32[] image, FGameTexHeader header, int32 widthInBlocks, int32 heightInBlocks ) { // Copy the data to a bitmap int32 width = widthInBlocks * header.BlockWidth; int32 height = heightInBlocks * header.BlockHeight; // https://stackoverflow.com/questions/24701703/c-sharp-faster-alternatives-to-setpixel-and-getpixel-for-bitmaps-for-windows-f DirectBitmap bitmap = new DirectBitmap(header.MaxWidth, header.MaxHeight); // Bitmap bitmap = new Bitmap( header.MaxWidth, header.MaxHeight, PixelFormat.Format32bppArgb ); for ( int32 y = 0; y < height; y++ ) { for (int32 col = 0; col < width; ++col) { bitmap.SetPixel(col, y, Color.FromArgb(image[y * width + col])); } // Rectangle area = new Rectangle( 0, y, width, 1 ); // BitmapData pixel_data = bitmap.LockBits( area, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb ); // Marshal.Copy( image, y * width, pixel_data.Scan0, width ); // bitmap.UnlockBits( pixel_data ); } // Copy the bitmap to a Paint.NET layer Surface mip_surface = Surface.CopyFromBitmap(bitmap.GetBitmap(), false ); // Surface mip_surface = Surface.CopyFromBitmap(bitmap, false); BitmapLayer mip_layer = new BitmapLayer( mip_surface ); mip_layer.Name = "Mip " + mip; mip_layer.Visible = ( mip == 0 ); mip_layer.BlendMode = LayerBlendMode.Normal; mip_layer.Opacity = 255; mippedDocument.Layers.Add( mip_layer ); bitmap.Dispose(); } Quote Link to comment Share on other sites More sharing options...
midora Posted September 24, 2021 Share Posted September 24, 2021 I wouldn't create an intermediate Bitmap. Just create a new BitmapLayer and set the pixels in a loop var layer = new BitmapLayer(pixelWidth, pixelHeight); doc.Layers.Add(layer); layer.Surface[column, row] = ... We just discussed what may be the fastest way to set the surface data from a raster. 1 Quote Link to comment Share on other sites More sharing options...
John Scott Posted September 24, 2021 Author Share Posted September 24, 2021 Worked a treat - thanks! Cheers John Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.