Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Security permisions for unmanaged code in .Net Applet

Security permisions for unmanaged code in .Net Applet

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharphtmldatabasesql-servergraphics
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheDen
    wrote on last edited by
    #1

    I'm developing - simple graphics editor, that should be placed on the web-site. It downloads the picture from the MSSQL server (i do this via WebService), edits this picture (putting some lines, dots, whatever), and than uploads changes to server. Since 2 part are ready, i have a terrible headache about the lastthing. The problem is: I draw primitives using Graphics, since this class don't know how to save the image drawn - I have to use unmanaged code to save it (BitBlt and stuff). Everything works ok, if it's standalone application - but i MUST use it as Applet,so there is a SecurityPermision Exception is raised when i'm trying to do unmanaged code. I tried to add the signature to the dll (sn -k), but somewhy IE doesn't want to load this applet. As far as i know, if user adds my DLL's public key to the trusted list - i can do unmanaged code (where he should put it). So the questions are: a) How i can save the image with drawn primitives (actually i need a stream to it, to upload to the server) using managed code b) How should add sign a dll, to let IE show it c) How should user add this to his trusted Assemblies list Here are the source codes: index.html IEControlv2.cs (windows control) new SecurityPermission(SecurityPermissionFlag.AllFlags).Assert(); CreateBitmapFromGraphics(gr,1,1,100,100); <---unmanaged code, where exception is raised. CodeAccessPermission.RevertAssert(); P.s. the .Net is 1.1 version

    D 1 Reply Last reply
    0
    • T TheDen

      I'm developing - simple graphics editor, that should be placed on the web-site. It downloads the picture from the MSSQL server (i do this via WebService), edits this picture (putting some lines, dots, whatever), and than uploads changes to server. Since 2 part are ready, i have a terrible headache about the lastthing. The problem is: I draw primitives using Graphics, since this class don't know how to save the image drawn - I have to use unmanaged code to save it (BitBlt and stuff). Everything works ok, if it's standalone application - but i MUST use it as Applet,so there is a SecurityPermision Exception is raised when i'm trying to do unmanaged code. I tried to add the signature to the dll (sn -k), but somewhy IE doesn't want to load this applet. As far as i know, if user adds my DLL's public key to the trusted list - i can do unmanaged code (where he should put it). So the questions are: a) How i can save the image with drawn primitives (actually i need a stream to it, to upload to the server) using managed code b) How should add sign a dll, to let IE show it c) How should user add this to his trusted Assemblies list Here are the source codes: index.html IEControlv2.cs (windows control) new SecurityPermission(SecurityPermissionFlag.AllFlags).Assert(); CreateBitmapFromGraphics(gr,1,1,100,100); <---unmanaged code, where exception is raised. CodeAccessPermission.RevertAssert(); P.s. the .Net is 1.1 version

      D Offline
      D Offline
      dnewmon
      wrote on last edited by
      #2

      The only way to do what you want here without using your unmanaged DLL is to create a Bitmap object and draw to it. Example: private Bitmap bmpCanvas; OnLoad(...) { bmpCanvas = new Bitmap(this.ClientSize.Width, this.ClientSize.Height); } OnResize(...) { bmpCanvas = new Bitmap(this.ClientSize.Width, this.ClientSize.Height); } OnDrawRect(...) { Graphics g = Graphics.FromImage(bmpCanvas); g.DrawRectangle(...); g.Dispose(); } OnPaint(object sender, PaintEventArgs pe) { pe.Graphics.DrawImage(bmpCanvas, 0, 0); } After this has been implemented you can start streaming fairly easily: // Pre-Buffer alittle maybe: MemoryStream stream = new MemoryStream(bmpCanvas.Width * cmpCanvas.Height * 3); // Stream as PNG (loss-less and has good compression): bmpCanvas.SaveImage(stream, ImageFormat.Png); You can then call stream.GetBuffer() and use stream.Length to send the data. You might want to ensure the user is complete and dispose of the Bitmap to reduce the memory footprint.

      T 1 Reply Last reply
      0
      • D dnewmon

        The only way to do what you want here without using your unmanaged DLL is to create a Bitmap object and draw to it. Example: private Bitmap bmpCanvas; OnLoad(...) { bmpCanvas = new Bitmap(this.ClientSize.Width, this.ClientSize.Height); } OnResize(...) { bmpCanvas = new Bitmap(this.ClientSize.Width, this.ClientSize.Height); } OnDrawRect(...) { Graphics g = Graphics.FromImage(bmpCanvas); g.DrawRectangle(...); g.Dispose(); } OnPaint(object sender, PaintEventArgs pe) { pe.Graphics.DrawImage(bmpCanvas, 0, 0); } After this has been implemented you can start streaming fairly easily: // Pre-Buffer alittle maybe: MemoryStream stream = new MemoryStream(bmpCanvas.Width * cmpCanvas.Height * 3); // Stream as PNG (loss-less and has good compression): bmpCanvas.SaveImage(stream, ImageFormat.Png); You can then call stream.GetBuffer() and use stream.Length to send the data. You might want to ensure the user is complete and dispose of the Bitmap to reduce the memory footprint.

        T Offline
        T Offline
        TheDen
        wrote on last edited by
        #3

        dnewmon, GREAT thanks - your solution killed few another rabbits :) I have only one problem - Eraser tool. So, assuming, i have the Bitmap - with the Transperent background. I draw on this Bitmap primitives - i want to be able somehow to erase their parts. Let's say i draw few lines, DrawLine(pen,1,1,100,100); DrawLine(pen,10,10,100,100); and want them to dissapear in the Rectangle(90,90,10,10); How can i do that? Is the Bitmap::LockBits method relevant? great 10x

        D 1 Reply Last reply
        0
        • T TheDen

          dnewmon, GREAT thanks - your solution killed few another rabbits :) I have only one problem - Eraser tool. So, assuming, i have the Bitmap - with the Transperent background. I draw on this Bitmap primitives - i want to be able somehow to erase their parts. Let's say i draw few lines, DrawLine(pen,1,1,100,100); DrawLine(pen,10,10,100,100); and want them to dissapear in the Rectangle(90,90,10,10); How can i do that? Is the Bitmap::LockBits method relevant? great 10x

          D Offline
          D Offline
          dnewmon
          wrote on last edited by
          #4

          I just figured out a way to do this: bmpCanvas = new Bitmap(320, 240, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bmpCanvas); g.Clear(Color.White); g.FillRectangle(new SolidBrush(Color.Red), 0, 0, 200, 200); g.FillEllipse(new SolidBrush(Color.FromArgb(255, 0, 0, 0)), 0, 0, 200, 200); g.Dispose(); bmpCanvas.MakeTransparent(Color.FromArgb(255, 0, 0, 0)); The ellipse is an "erased" region and considered transparent. I tried using Color.Transparent instead of Color.FromArgb(255, 0, 0, 0) but had no luck. NOTE: The MakeTransparent(...) call has to be made every time you erase a region. Enjoy, David

          T 1 Reply Last reply
          0
          • D dnewmon

            I just figured out a way to do this: bmpCanvas = new Bitmap(320, 240, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bmpCanvas); g.Clear(Color.White); g.FillRectangle(new SolidBrush(Color.Red), 0, 0, 200, 200); g.FillEllipse(new SolidBrush(Color.FromArgb(255, 0, 0, 0)), 0, 0, 200, 200); g.Dispose(); bmpCanvas.MakeTransparent(Color.FromArgb(255, 0, 0, 0)); The ellipse is an "erased" region and considered transparent. I tried using Color.Transparent instead of Color.FromArgb(255, 0, 0, 0) but had no luck. NOTE: The MakeTransparent(...) call has to be made every time you erase a region. Enjoy, David

            T Offline
            T Offline
            TheDen
            wrote on last edited by
            #5

            David, Great thanks for help

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups